instanceof1 [자바] equals() & hashCode() 재정의 알고리즘을 풀던 중 Node라는 class를 만들어 set에 넣어 contains 메서드를 이용해 비교하려고했다. 객체를 비교하기 위해서는 클래스에 equals와 hashCode 메서드를 재정의해야했다. static class Node { int a; int b; public Node(int a, int b) { this.a = a; this.b = b; }}public static void main(String[] args) throws IOException { Node left = new Node(1, 2); Node right = new Node(1, 2); System.out.println(Objects.equals(left, righ.. 2024. 5. 16. 이전 1 다음