I have some code that looks a bit like this (it's simplified here):
public Optional<String> parseInput(String input){
Pattern pattern = Pattern.compile("([A-Za-z]+)([0-9]{2}|[0-9]{4})");
Matcher matcher = pattern.matcher(input);
return Optional.of(matcher.find())
.filter(t -> t) // .filter(Function.identity())
.map(ignore -> matcher.group(1));
}
But it fails with an error:
Error: incompatible types: no instance(s) of type variable(s) T exist so that java.util.function.Function<T,T> conforms to java.util.function.Predicate<? super java.lang.Boolean>
What is going on here, and why is it designed this way?