I write here to draw attention to this incorrect answer by polygenelubricants to a question about supertype bounds in Java generics. The answer is accepted and highly upvoted. Both the question poster and answer poster don't respond to comments and seem to have left the site.
I'd like to encourage everyone to downvote that answer and instead upvote this correct answer by Rotsor.
The incorrect statement that is made is that supertype bounds on generic parameters would not make sense as a language construct.
The matter is complicated by a few different things:
- It concerns a subtle corner case of the type system which it takes knowledge and effort to understand. It is also probably of interest mostly for type system enthusiasts.
- The accepted answer does not make the incorrect statement explicitly. But from its introduction and the chosen examples it is clear that this is its main point.
- The answer provides several examples of when super type bounds would not be useful, but it overlooks examples where they would be. This makes it harder to spot the error in the reasoning.
- The question uses Java arrays as an example. This is unfortunate as the covariance of arrays makes the main problem about supertype bounds less clear.
All this makes the issue a bit tricky to understand. I hope however that there are enough type system enthusiasts around to make things right here.