Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

records java final

public class Person {

    private final String name;
    private final String address;

    public Person(String name, String address) {
        this.name = name;
        this.address = address;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, address);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (!(obj instanceof Person)) {
            return false;
        } else {
            Person other = (Person) obj;
            return Objects.equals(name, other.name)
              && Objects.equals(address, other.address);
        }
    }

    @Override
    public String toString() {
        return "Person [name=" + name + ", address=" + address + "]";
    }

    // standard getters
}
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #records #java #final
ADD COMMENT
Topic
Name
9+9 =