Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何修复不明确的方法引用?_Java_Java 8 - Fatal编程技术网

Java 如何修复不明确的方法引用?

Java 如何修复不明确的方法引用?,java,java-8,Java,Java 8,如何在不修改class案例的情况下解决class测试中的两条错误行 class Case { public boolean isEmpty() { return true; } public static boolean isEmpty(Case t) { return true; } } public class Test { public static void main(String[] args) {

如何在不修改class
案例的情况下解决class
测试中的两条错误行

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          
    }
}
类案例{
公共布尔值为空(){
返回true;
}
公共静态布尔值为空(案例t){
返回true;
}
}
公开课考试{
公共静态void main(字符串[]args){

Predicate forNonStaticMethod=Case::isEmpty;//您可以使用lambda表达式而不是方法引用:

Predicate<Case> forNonStaticMethod = c -> c.isEmpty();
Predicate<Case> forStaticMethod = c -> Case.isEmpty(c);
谓词forNonStaticMethod=c->c.isEmpty();
谓词forStaticMethod=c->Case.isEmpty(c);