Skip to content

정적 팩터리 방식의 싱글턴의 세번째 장점: 정적 팩터리의 메서드 참조를 Supplier로 사용할 수 있다. #66

Description

@KimChanJin97

1

1

Supplier 인터페이스는 JAVA8부터 함수형 프로그래밍을 지원하기 위해 java.util.function 패키지에 추가되었습니다. Supplier 인터페이스에는 매개변수가 없는 메서드 T get()를 가지고 있습니다.

질문1.
Elvis 클래스에서 Supplier를 상속(implements)한 적도 없고, get() 메서드를 오버라이딩한 적도 없는데 supplier1, supplier2 참조변수들은 어떻게 get() 메서드를 사용할 수 있는 걸까요?

질문2.
그냥 Elvis 참조타입 elvis4 참조변수를 사용하면 더 심플하지 않을까요? 왜 굳이 Supplier 참조타입 supplier1, supplier2 참조변수를 사용하는 걸까요?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effective Java 3E이펙티브 자바 관련 질의 응답

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions