Long id; private final String name; public Person(Long id, String name) { this.id = id; this.name = name; } public Long getId() { return id; } public String getName() { return name; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final User user = (User) o; if (!id.equals(user.id)) return false; return name.equals(user.name); } @Override public int hashCode() { int result = id.hashCode(); result = 31 * result + name.hashCode(); return result; } @Override public String toString() { return "User{" + "id=" + id + ", name='" + name + '\'' + '}'; } public User withId(Long id) { return new User(id, name); } public User withName(String name) { return new User(id, name); } public static Builder { private Long id; private String name; public User build() { return new User(id, name); } public Builder id(Long id) { this.id = id; return this; } public Builder name(String name) { this.name = name; return this; } } } data class User( val id: Long, val name: String ) Java Kotlin