我很好奇Java的类型擦除的具体规则会导致以下情况发生:
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();
}
}
是否因为如果您使用原始类型,即使在编译时,该类型成员的所有泛型信息都将被删除?