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 */
1313public 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
97106class Person {
98107 String name ;
99108
@@ -108,7 +117,6 @@ public String toString() {
108117 '}' ;
109118 }
110119}
111-
112120class 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