-
Notifications
You must be signed in to change notification settings - Fork 322
Closed
Description
I've stumbled upon difficulty invoking super constructor/methods when a generic super class allows null types and the subclass declares the generic type as null. A few examples:
null super constructor argument fails
@NullMarked
private static class A<T extends @Nullable Object> {
A(T o) {}
}
@NullMarked
private static class B extends A<@Nullable Object> {
B() {
super(null); // fails
}
}null super method invocation fails
@NullMarked
private static class A<T extends @Nullable Object> {
void m(T t) {}
}
@NullMarked
private static class B extends A<@Nullable Object> {
void test() {
m(null); // fails
}
}The example below compiles and is similar to the previous that fails except that the method invocation is not in the child class.
@NullMarked
private static class A<T extends @Nullable Object> {
void m(T t) {}
}
@NullMarked
private static class B extends A<@Nullable Object> {
}
static void test() {
new B().m(null); // compiles
}Metadata
Metadata
Assignees
Labels
No labels