Java language
Record declaration
Declares a final record class with component fields, accessors and a canonical constructor. Generated equality is component based.
Formal Syntax & Structure
java syntaxjava
record Shelf(String aisle, int number) {}Working Example
Example Snippetjava
public class Main { record Shelf(String aisle, int number) {} public static void main(String[] args) { Shelf a = new Shelf("B", 3); Shelf b = new Shelf("B", 3); System.out.println(a.aisle() + a.number()); System.out.println(a.equals(b)); System.out.println(a == b); System.out.println(a.hashCode() == b.hashCode()); }}