2017-02-14 2 views
2

クラスTestの2つのエラーラインをクラスCaseに変更せずに解決するにはどうすればよいですか?あいまいなメソッド参照を修正するには?

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); 
関連する問題