🌐 AI搜索 & 代理 主页
Skip to content

Sublcass<@Nullable Object> does not allow null super invocations #1246

@rwinch

Description

@rwinch

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions