4 ms·
> If Java had generics in the beginning, it would look a lot different and the type system would be more powerful and safe. And conceivably a good deal faster,
by MaxBarraclough 8y ago
> If Java had generics in the beginning, it would look a lot different and the type system would be more powerful and safe.
And conceivably a good deal faster, too. My understanding is that the JVM is required to constantly perform runtime type checks.
- monocasa 8y agoYeah, it either has to cast from Object all the time, or spend JIT compiler time and memory figuring out if it can elide those checks (probably with exception code for when it guesses wrong).
- leshow 8y agoand pointer chasing too right? unless the runtime can optimize, every generic sits behind a pointer.
- icedchai 8y agoGood deal faster? I seriously doubt it. My understanding are generics are purely a compile time feature and does not effect run time. I remember Java before generics: tons of casting from Object. The compiler is doing the same thing.
- mcculley 8y agoThose casts are still there. The compiler puts them in and the JVM has to execute them.
- icedchai 8y agoYes. And my point is they'd be there anyway, with or without generics. It's not "generics" making the JVM any slower.
- mcculley 8y agoIf the types were reified, the compiler and the JVM would know what type was there. No cast would be needed.
- MaxBarraclough 8y ago> they'd be there anyway No. That's the point.