Created
April 25, 2020 11:12
-
-
Save jon-ruckwood/3e4f0bddea748fe2ab95d6e6a515d246 to your computer and use it in GitHub Desktop.
Compile with `--enable-preview`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Java14RecordExample { | |
public static void main(String[] args) { | |
var p = new Person("Boz", "Scaggs"); | |
System.out.println("toString(): " + p); | |
System.out.println("---"); | |
System.out.println("Howdy " + p.name() + "!"); | |
} | |
} | |
record Person(String firstName, String lastName) { | |
public Person { | |
requireNonNull(firstName, "firstName is required"); | |
requireNonNull(lastName, "lastName is required"); | |
} | |
public String name() { | |
return firstName + " " + lastName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment