I’m using the interface Predicate<T> from com.google.common.base (Google Guava)
But I don’t know how to have the equals() method works…
Why do I get false when I type something like this :
Predicate<Object> PredicateD = new Predicate<Object>(){
@Override public boolean apply(Object number) {
return ((number instanceof Double) && (Math.floor((Double)number) == (Double)number));
}
};
Predicate<Object> PredicateM = new Predicate<Object>(){
@Override public boolean apply(Object number) {
return ((number instanceof Double) && (Math.floor((Double)number) == (Double)number));
}
};
System.out.println(PredicateD.equals(PredicateM));
Thanks in advance for your Help,
You’re creating two different anonymous inner classes, but neither of them is overriding
equals, so you’ll get the default implementation, whereby any two non-equal references are considered non-equal.As the values of
PredicateDandPredicateMare different references,equalsreturns false.