Assume we have a predicate declared as Predicate<? super SomeClass>
. I would naively expect it to be applicable to any superclass of SomeClass
up the hierarchy, including Object
.
However this predicate is not applicable to Object
. I get the following error:
The method test(capture#3-of ? super SomeClass) in the type Predicate is not applicable for the arguments (Object)
Demo.
Why is Predicate<? super SomeClass>
not applicable to an instance of Object
?
The code:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.net.URL;
import java.util.function.Predicate;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Predicate<? super URL> p = u -> u.getFile().isEmpty();
p.test(new Object());
}
}