2017-02-14 1 views
2

Case 클래스의 수정없이 Test 클래스의 두 오류 라인을 해결하는 방법은 무엇입니까?모호한 메소드 참조를 수정하는 방법은 무엇입니까?

class Case { 
    public boolean isEmpty() { 
     return true; 
    } 

    public static boolean isEmpty(Case t) { 
     return true; 
    } 
} 

public class Test { 
    public static void main(String[] args) { 
     Predicate<Case> forNonStaticMethod = Case::isEmpty;//<--TODO: fix compile error: 
     Predicate<Case> forStaticMethod = Case::isEmpty;//<--TODO: fix compile error: 
     //Ambiguous method reference: both isEmpty() and isEmpty(Case) from the type Case are eligible   
    } 
} 

답변

4
당신은 방법 참조 대신 람다 표현식을 사용할 수 있습니다

:

Predicate<Case> forNonStaticMethod = c -> c.isEmpty(); 
Predicate<Case> forStaticMethod = c -> Case.isEmpty(c); 
관련 문제