Skip to content

Commit

Permalink
effective java 3e
Browse files Browse the repository at this point in the history
  • Loading branch information
genie-youn committed Jan 27, 2019
1 parent f0f5a16 commit 2285fc9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Java/Effective_Java_3E.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,7 @@ static Comparator<Object> hashCodeOrder = new Comparator<>() {

static Comparator<Object> hashCodeOrder = Comparator.comparingInt(o -> o.hashCode());
```

##### 결론

순서를 고려해야 하는 값 클래스를 작성한다면 꼭 `Comparable` 인터페이스를 구현하여, 그 인스턴스를 쉽게 정렬하고, 검색하고, 비교 기능을 제공하는 컬렉션과 어우러지도록 해야한다. `compareTo` 메서드에서 필드의 값을 비교할 때 <와 >연산자는 쓰지 말아야한다. 그 대신 박싱된 기본 타입 클래스가 제공하는 정적 `compare` 메서드나 `Comparator` 인터페이스가 제공하는 비교자 생성 메서드를 사용하자.

0 comments on commit 2285fc9

Please sign in to comment.