2

How to resolve the two error lines in class Test without modification on class 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          
    }
}
Eran
  • 387,369
  • 54
  • 702
  • 768
seven
  • 35
  • 7

1 Answers1

4

You can use lambda expressions instead of methods references :

Predicate<Case> forNonStaticMethod = c -> c.isEmpty();
Predicate<Case> forStaticMethod = c -> Case.isEmpty(c);
Eran
  • 387,369
  • 54
  • 702
  • 768