Hacker News new | ask | show | jobs
by HideousKojima 844 days ago
No, Java generics are basically syntactic sugar over casts, which is why types are erased at runtime when you're trying to debug. Performance also isn't as good as for C# generics since the Java approach limits optimizations.
2 comments

Haskell also has type erasure. It’s an implementation detail, or are you saying that Haskell does not have proper generics?
I don't know the specifics of Haskell's implementation but if it's mostly the same as Java's then yeah?
That's a minor implementation detail that devs almost never have to think about.
You'll run into it with generic arrays[0] in Java which are reasonably common.

[0]https://www.baeldung.com/java-generic-array

As someone who works with Java all the time I'm the first to admit that something like TypeToken in GSON or comparable things in other libraries is not the greatest of things. I've also more than once wished I could to if(xy instanceof List<Something>), which you cannot do in Java. Can you work around it? Sure. Do I understand why Java has it? Yes. But "minor" .. no, it's not so minor in my experience.