Re: Java generics and type erasure
Andreas Leitgeb wrote:
Lew wrote:
OK, so I shouldn't have said "bytecode", I should've said "class file", two
terms that I treat interchangeably. It's in the freaking CLASS FILE, right?
Isn't that the thing that gets used at runtime? Doesn't the generic
information in THE CLASS FILE get ignored at runtime just like I said?
It's not so much a question of whether the generic information of a
class file (like java/util/ArrayList.class) is used or not, but rather
whether the generic information of a particular *use* of that class was
in the *using* code's class-file, which I think isn't:
... = new ArrayList<ArrayList<ArrayList<Boolean>>>();
Ah, gotcha.
To eliminate my inverted way of expressing it, then, generics effectively
don't exist at runtime because erasure occurs before runtime. Generics errors
occur at compilation. Exceptions not prevented by the generics checks at
compilation occur at runtime, just as they would have were generics never
used, because at runtime the erasure has already occurred and the generics
information effectively no longer exists (but for some non-relevant classfile
information).
Thank you all for helping to clarify this.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg