79221441

Date: 2024-11-25 02:18:45
Score: 0.5
Natty:
Report link

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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Why is
  • Low reputation (0.5):
Posted by: Smola