Skip to content

124p 3.7.3 3단계 부분! #40

Discussion options

You must be logged in to vote

질문 1.

우선 2가지 말씀드리자면,

  1. Comparator 인터페이스에는 compareTo라는 메서드는 존재하지 않고 compare과 comparing과 같은 비교 메서드가 존재하는데 그 중, comparing이 정적 메서드 입니다.
  2. compareTo는 Comparable이라는 인터페이스 안에 있는 메서드 입니다.

그래서
Comparator는 Comparable 키를 추출해서 Comparator 객체로 만드는 Function 함수를 인수로 받는 정적 메서드 comparing을 포함한다.라는 말은

//Comparator 인터페이스 중 일부
//comparing 메서드
public static <T, U extends Comparable<? super U>> Comparator<T> comparing(
        Function<? super T, ? extends U> keyExtractor)
{
    Objects.requireNonNull(keyExtractor);
    return (Comparator<T> & Serializable)
        (c1, c2) -> keyExtractor.apply(c1).compareTo(keyExtractor.apply(c2));
}
public static <T, U extends Comparable<? super U>> Comparator<T> comparing(
   …

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@BvrPark
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Youngju-Jang
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants