4 ms·
Do Java generics work like that? I thought the JVM did not know about the generics as the types are erased at compile time.
by enitihas 10y ago
Do Java generics work like that? I thought the JVM did not know about the generics as the types are erased at compile time.
- eonwe 10y agoJVM doesn't know about generic types at the runtime. There's no specialization of HashMaps, it's just arrays of points to objects all around. With project Valhalla: https://en.wikipedia.org/wiki/Project_Valhalla_(Java_language) https://en.wikipedia.org/wiki/Project_Valhalla_(Java_languag... there's been talk about specialization for value types.
- enitihas 10y agoI too thought the same. That's why pcwalton's comment confused me.
- pjmlp 10y agoIt is already available for those that want to play with it. https://adoptopenjdk.gitbooks.io/adoptopenjdk-getting-started-kit/content/en/openjdk-projects/valhalla.html https://adoptopenjdk.gitbooks.io/adoptopenjdk-getting-starte...
- pcwalton 10y agoRust generics do. Java's don't.