Skip to content

Commit f5329b8

Browse files
author
Araf Karsh Hamid
committed
Added Java 16 Examples
1 parent 71f43d1 commit f5329b8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/java16/RecordExample.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,31 @@
2929

3030
/**
3131
* Java 16 Examples
32-
* Record Example
32+
* Record Example - To Eliminate the verbosity in Creating Java Beans
33+
* - Public Accessor Methods
34+
* - Constructor
35+
* - Equals
36+
* - Hashcode
37+
* - toString
38+
* are automatically created
39+
* You can have custom implementations of the above methods..
40+
* Compact Constructors are allowed only in Records.
41+
* You cant add Instance Variables or Instance Initializers
3342
*
3443
* @author: Araf Karsh Hamid
3544
* @version:
3645
* @date:
3746
*/
3847
public class RecordExample {
3948

49+
record User(String firstName, String lastName, String email, String phone, String dept) {}
50+
4051
public static void main (String[] args) {
41-
// WIP
52+
// Java 16
53+
System.out.println("JAVA 16 >>>>>--------------------------------------------------------");
54+
System.out.println("Record Example. ");
55+
User adminUser = new User("Jane", "Doe", "[email protected]", "111-222-3456", "Engineering");
56+
System.out.println("Admin User = "+adminUser.firstName() + " " + adminUser.lastName());
57+
System.out.println("Admin User = "+adminUser);
4258
}
4359
}

0 commit comments

Comments
 (0)