Question: Java 14 introduces a syntactic sugar called a record . Its a short-hand notion for creating an immutable class that provides boilerplate code for a
Java 14 introduces a syntactic sugar called a record. Its a short-hand notion for creating an immutable class that provides boilerplate code for a constructor, getters, equals(), hashCode(), and toString() methods. Write a plain Java class equivalent to the Place record below.
public record Place (int x, int y) {}
// Example use Place p = new Place(10, 20); System.out.println(p.x() + ", " + p.y()); System.out.println(p.equals(new Place(10,20)); System.out.println(p.hashCode()); System.out.println(p); // toString() is called
Submit source code file and screenshots of sample runs.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
