Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 06d234b

Browse files
record within java 14
1 parent b053671 commit 06d234b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

‎src/main/java/others/youtube/BeyondJava8.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Life Beyond Java 8, by Trisha Gee / JetBrains Technology Day for Java (2020)
1010
* https://www.youtube.com/watch?v=gKestt55Q4M
11-
* @todo java 13 and above
11+
* @todo java 15 and above
1212
*/
1313
public class BeyondJava8 {
1414

@@ -19,8 +19,17 @@ public static void main( String[] args ) {
1919
//predicateNot();
2020
//newSwitchStatement(new Random().nextInt());
2121
//textBlocks();
22-
Person p1 = new Employee("zaki");
23-
instanceOfInJava14(p1);
22+
/*Person p1 = new Employee("zaki");
23+
instanceOfInJava14(p1);*/
24+
usingRecordInJava14();
25+
}
26+
27+
private static void usingRecordInJava14() {
28+
User user = new User(1, "Trisha");
29+
//with record we get overridden methods out of the box...
30+
System.out.println("user.id() = " + user.id());
31+
System.out.println("user.name() = " + user.name());
32+
System.out.println("user.toString() = " + user.toString());
2433
}
2534

2635
private static void instanceOfInJava14(Person person) {
@@ -93,7 +102,7 @@ public static void unmodifiableList(){
93102
}
94103
}
95104

96-
105+
//for pattern matching
97106
class Person{
98107
String name;
99108

@@ -108,7 +117,6 @@ public String toString() {
108117
'}';
109118
}
110119
}
111-
112120
class Employee extends Person{
113121
public Employee(String name) {
114122
super(name);
@@ -120,3 +128,11 @@ public String getEmployeeName(){
120128
}
121129

122130
}
131+
132+
133+
record User(int id, String name){
134+
135+
}
136+
137+
138+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /