-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCountryClass.java
More file actions
40 lines (35 loc) 路 1.05 KB
/
Copy pathCountryClass.java
File metadata and controls
40 lines (35 loc) 路 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package samples.jdk16;
/**
* This is what a regular data class (which just stores data)
* looks like in traditional Java code.
* We have attributes, getters and possibly a {@link #toString()} method.
* If we don't want to change object attribute values,
* we don't include setters.
*
* <p>After JDK 16, such a class can be replaced by a Record,
* such as {@link samples.jdk16.Country}, which removes all boilerplate code,
* providing the same features.</p>
*/
public final class CountryClass {
private final String name;
private final String continent;
public CountryClass(String name, String continent) {
this.name = name;
this.continent = continent;
}
public String getName() {
return name;
}
public String getContinent() {
return continent;
}
/**
* Uses the {@link String#formatted(Object...)} method
* introduced in JDK 15.
* @return
*/
@Override
public String toString() {
return "Country[name= %s, continent=%s]".formatted(name, continent);
}
}