I am curious about what specific rules of Java's type erasure cause the following to happen:
import java.util.function.Supplier;
public class TypeCheckerWeirdness {
public static class Meow<S extends Meow> {
public Supplier<Boolean> hungry;
}
public static void main(String[] args) {
Meow<?> instanceA = new Meow<>();
Meow instanceB = new Meow<>();
// fine
boolean x1 = instanceA.hungry.get();
// incompatible types. Found: 'java.lang.Object', required: 'boolean'
boolean x2 = instanceB.hungry.get();
}
}
Is it because of that if you use a raw type, all generics information on the members of the type will be erased even at the compilation time?