I am new to java8 and I was trying to understand this piece of code. This is the piece of code:
Stream.of("A", "B", "C").anyMatch(someObj.getStringValue()::equalsIgnoreCase)
someObj.getStringValue()
references some object and the getStringValue()
returns some String value.
What is the equivalent predicate of the method reference being passed into anyMatch(...)
?
My understanding was this would be equivalent to:
Predicate<String> p = new Predicate<String>() {
@Override
public boolean test(String t) {
return someObject.getStringValue().equalsIgnoreCase(t);
}
}
Stream.of("A", "B", "C").anyMatch(p)
With this I get the error "Local variable someObject
defined in an enclosing scope must be final or effectively final." Any explanation on this is appreciated.