equals() method for classes with bidirectional association
问题 I am trying to implement equals method for Java classes Book and Chapter in my application. Book has a set of Chapter s, while a Chapter has an associated Book . The bidirectional association is shown as below: class Book{ private String isbn; private String name; private Date publishDate; private Set<Chapter> chapters; ... public boolean equals(Object o){ if(o == this){ return true; } if (!(o instanceof Book)){ return false; } Book book = (Book)o; if( (this.isbn.equals(book.getIsbn()) ) &&