With all respect I think you've missed the point of the article. Of course it does not apply to Lists, since they both produce and consume objects. It could apply to immutable lists, where you cannot add/set items, only get.
My point was to show that classes with generic types that are used in producer role are not detected by Java compiler as safe to cast, when covariant types are used.
I see. Thanks for the clarification. I'm still not sure that this technique is really safe and won't be abused in some very unobvious ways, but that's completely different story. :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
With all respect I think you've missed the point of the article. Of course it does not apply to
List
s, since they both produce and consume objects. It could apply to immutable lists, where you cannot add/set items, only get.My point was to show that classes with generic types that are used in producer role are not detected by Java compiler as safe to cast, when covariant types are used.
I see. Thanks for the clarification. I'm still not sure that this technique is really safe and won't be abused in some very unobvious ways, but that's completely different story. :)