Why is RestrictingType<?> not within the bounds of T?
Because ?
is an unknown type because T
is actually not bound in RestrictingType<T>
. It can be anything, like Integer. Therefore the compiler cannot know if ?
implements RestrictingType
and consequently SelfReferringInterface
.
And why is the functionaly similar ? extends RestrictingType<?> no problem?
Because now you've bounded ?
with RestrictingType<?>
which means compiler knows it's a RestrictingType
and consequently SelfReferringInterface
.
Also, funny, but this compiles and runs on my Java 21.