String name; } // ಛఆͷϑΟʔϧυΛআ֎͢Δ͜ͱͰ͖Δ @EqualsAndHashCode(exclude = "age") class EqualsAndHashCodeExample2 { private int id; private String name; private int age; } public class EqualsAndHashCodeExample { private int id; private String name; @Override public boolean equals(final Object o) { … } @Override public int hashCode() { … } } public class EqualsAndHashCodeExample2 { private int id; private String name; private int age; // age༻͞Εͳ͍ @Override public boolean equals(final Object o) { … } @Override public int hashCode() { … } }
int id; private String name; } @RequiredArgsConstructor class ConstructorExample2 { private final int id; private String name; } public class ConstructorExample { private int id; private String name; public ConstructorExample( final int id, final String name) { this.id = id; this.name = name; } public ConstructorExample() { } } class ConstructorExample2 { private final int id; private String name; public ConstructorExample2(final int id) { this.id = id; } }
String name; } public final class ValueExample { private final int id; private final String name; public ValueExample( final int id, final String name) { this.id = id; this.name = name; } public int getId() { return this.id; } public String getName() { return this.name; } @Override public boolean equals(final Object o) { … } @Override public int hashCode() { … } @Override public String toString() { … } }
new ArrayList<String>(); list.add("a"); list.add("b"); val item = list.get(0); System.out.println(item); } public static void main(String[] args) { final ArrayList<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); final String item = list.get(0); System.out.println(item); }