Encapsulating the state

The record classes encapsulate the fields, providing default implementations of JavaBean-style accessor methods (public methods to set the values of fields). The values can be assigned during the initialization of data class instances, using their constructors. 

For example, let's revisit the Emp data class and its decompiled version from a previous section:

record Emp(String name, int age) { }

final class Emp extends java.lang.DataClass { final String name; final int age; public Emp(String name, int age) { this.name = name; this.age = age; } // deconstructor // public accessor methods // default implementation of equals, hashCode, and toString }

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.189.228