DEV Community

Discussion on: Pains of Java generics solved in Kotlin

Collapse
 
rapasoft profile image
Pavol Rajzak

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.

Collapse
 
voins profile image
Alexey Voinov

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. :)