Java – predicate method equals()
•
Java
I'm using the interface predict < T > from com google. common. base(Google Guava)
But I don't know how to make the equals () method effective
Why do I make an error when I enter the following?
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));
Thank you for your help,
Solution
You are creating two different anonymous inner classes, but neither of them will override equals, so you will get the default implementation, so any two unequal references are treated as unequal
Equals returns false because the values of predicted and predicted are different references
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码