public record Person (String name, String address) {}
This creates a class Person, inheriting from java.lang.Record. The compiler automatically generates accessor methods for the fields (i.e., name and address) and the default methods of Object, i.e., equals, hashcode, and toString.
These are implemented as invokedynamic calls to java/lang/runtime/ObjectMethods.bootstrap. The bootstrap method seems sufficient straightforward.
The toString one seems to be the only problematic of the three, especially as we do some hacky stuff around toString by having two of them, which differ in the descriptor only.
Java 15+ has the
Record
class feature, which allows the creation of concise objects with default implementations of the standard methods.The code would look like this, for example:
This creates a class
Person
, inheriting fromjava.lang.Record
. The compiler automatically generates accessor methods for the fields (i.e.,name
andaddress
) and the default methods ofObject
, i.e.,equals
,hashcode
, andtoString
. These are implemented asinvokedynamic
calls tojava/lang/runtime/ObjectMethods.bootstrap
. The bootstrap method seems sufficient straightforward.The toString one seems to be the only problematic of the three, especially as we do some hacky stuff around
toString
by having two of them, which differ in the descriptor only.