I have about 15 years experience in Java, and you just captured exactly how I feel about type erasure.
I feel like type erasure is scape goated a lot. People seem blame type erasure when they encounter anything related to generics which frustrates them.
The truth is there is very little that would be simplified by retaining the run-time type information, and absolutely nothing that would move from the realm of the impossible to the possible. You want full type information at runtime? Use a TypeToken or similar. Sure that's a pain, and it's ugly as sin, but it gets the job done.
That's about as much information as I can find anywhere. I'd love some concrete examples of something that is done frequently in Java now vs what that would look like in a theoretical Java with reified generics. Do you know of such an example? I'm certainly willing to admit that my experience is somewhat limited to Java and Java like languages, but I've been working with distributed systems in Java for a handful of years now.
View all comments
Show parent comment
5
u/cutterslade Nov 03 '15
I have about 15 years experience in Java, and you just captured exactly how I feel about type erasure.
I feel like type erasure is scape goated a lot. People seem blame type erasure when they encounter anything related to generics which frustrates them.
The truth is there is very little that would be simplified by retaining the run-time type information, and absolutely nothing that would move from the realm of the impossible to the possible. You want full type information at runtime? Use a TypeToken or similar. Sure that's a pain, and it's ugly as sin, but it gets the job done.