JDK-8262133 : Release Note: JEP 395: Records
  • Type: Sub-task
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 16
  • Priority: P3
  • Status: Closed
  • Resolution: Delivered
  • Submitted: 2021-02-22
  • Updated: 2021-12-05
  • Resolved: 2021-04-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16Resolved
Description
Records have been added to the Java language. Records are a new kind of class in the Java language. They act as transparent carriers for immutable data with less ceremony than normal classes.

Since nested classes were first introduced to Java, with the exception of static final fields initialized by constant expressions, nested class declarations that are inner have been prohibited from declaring static members. This restriction applies to non-static member classes, local classes, and anonymous classes. 

[JEP 384: Records (Second Preview)](https://openjdk.java.net/jeps/384) added support for local interfaces, enum classes, and record classes, all of which are static definitions. This was a well-received enhancement, permitting coding styles that reduce the scope of certain declarations to local contexts. 

While [JEP 384](https://openjdk.java.net/jeps/384) allowed for static local classes and interfaces, it did not relax the restriction on static member classes and interfaces of inner classes. An inner class could declare a static interface inside one of its method bodies, but not as a class member. 

As a natural next step, [JEP 395](https://openjdk.java.net/jeps/395) further relaxes nesting restrictions, and permits static classes, methods, fields, etc., to be declared within inner classes.
 
For further details, see [JEP 395](https://openjdk.java.net/jeps/395). 
Comments
Since nested classes were first introduced to Java, nested class declarations that are inner have been prohibited from declaring static members, with the exception of static final fields initialized by constant expressions. This restriction applies to non-static member classes, local classes, and anonymous classes. [JEP 384](https://openjdk.java.net/jeps/384), the second preview of Record Classes added support for local interfaces, enum classes, and record classes, all of which are static definitions. This was a well-received enhancement, permitting coding styles that reduce the scope of certain declarations to local contexts. While [JEP 384](https://openjdk.java.net/jeps/384) allowed for static local classes and interfaces, it did not relax the restriction on static member classes and interfaces of inner classes. So an inner class can declare a static interface inside one of its method bodies, but not as a class member. As a natural next step, [JEP 395](https://openjdk.java.net/jeps/395) proposes further relaxing nesting restrictions, permitting static classes, methods, fields, etc., to be declared within inner classes.
06-04-2021