On 2020-08-07 23:39, H. S. Teoh wrote:
They are *very* different.
Java generics are based on "type erasure", i.e., at the syntactic level,
containers are parametrized with the element types, but at the
implementation level, the element types are merely "erased" and replaced
with Object (a top type of sorts). There is only one container
instantiation, which is shared across all parametrizations. I don't
know exactly why this approach was chosen
I'm guessing a strong reason was to be backwards compatible with earlier
versions of Java.
The type erasure is also most likely the reason why Java generic types
don't accept primitive types. They need to be boxed, i.e. `int` need to
be wrapped in an object of type `Integer`.
--
/Jacob Carlborg