News for hackers. Stuff that matters.
Re:Modern programming languages require generics by titzer on Tuesday May 24, 2022 @04:16PM (#31497062)
The javac source compiler erases source-level types and inserts casts into the bytecode (at usage sites, not within the generic class). So if you have ArrayList<T>, it will generate one version of ArrayList. But usage sites will have casts inserted where necessary. In particular, in a use of put() on the outside doesn't need a cast (because the single implementation of ArrayList uses Object underneath), but get() will have a cast from Object to String at the call site.

There are no comments on this comment yet.