I wonder why this code even compiles. Because here what we have is a Predicate
which its type could be String or any of its super type. Obviously, length()
is not available in Object class which is suitable for this predicate.
Predicate<? super String> predicate = s -> s.length() > 3;
Stream.of("cat", "bat", "rat", "doggy").filter(predicate).forEach(System.out::println);
Can anyone describe a situation where we must need these type of a bounded type predicate?