File tree Expand file tree Collapse file tree
core-java-modules/core-java-15
src/main/java/com/baeldung/whatsnew Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151 <configuration >
5252 <release >${maven.compiler.release} </release >
5353 <compilerArgs >--enable-preview</compilerArgs >
54- <source >15 </source >
55- <target >15 </target >
54+ <source >14 </source >
55+ <target >14 </target >
5656 </configuration >
5757 </plugin >
5858 <plugin >
Original file line number Diff line number Diff line change 33/**
44 * Java record with a header indicating 2 fields.
55 */
6- public record Person (String name , int age )
7- {
6+ public record Person (String name , int age ) {
87 /**
98 * Public constructor that does some basic validation.
109 */
11- public Person
12- {
13- if (age < 0 )
14- {
10+ public Person {
11+ if (age < 0 ) {
1512 throw new IllegalArgumentException ("Age cannot be negative" );
1613 }
1714 }
Original file line number Diff line number Diff line change 22
33import java .util .Date ;
44
5- public non-sealed class Employee extends Person
6- {
7- public Date getHiredDate ()
8- {
5+ public non-sealed class Employee extends Person {
6+ public Date getHiredDate () {
97 return new Date ();
108 }
119}
Original file line number Diff line number Diff line change 11package com .baeldung .whatsnew .sealedclasses ;
22
3- public final class Manager extends Person
4- {
3+ public final class Manager extends Person {
54}
Original file line number Diff line number Diff line change 22
33import java .util .Date ;
44
5- public sealed class Person permits Employee , Manager
6- {
5+ public sealed class Person permits Employee , Manager {
76 /**
87 * Demonstration of pattern matching for instanceof
98 *
109 * @param person A Person object
1110 * @return
1211 */
13- public static void patternMatchingDemo (Person person )
14- {
15- if (person instanceof Employee employee )
16- {
12+ public static void patternMatchingDemo (Person person ) {
13+ if (person instanceof Employee employee ) {
1714 Date hiredDate = employee .getHiredDate ();
1815 }
1916
20- if (person instanceof Employee employee && employee .getHiredDate () != null )
21- {
17+ if (person instanceof Employee employee && employee .getHiredDate () != null ) {
2218 Date hiredDate = employee .getHiredDate ();
2319 }
2420 }
You can’t perform that action at this time.
0 commit comments