[jdom-interest] JDOM with generics
Victor Toni
victor.toni at ebuconnect.de
Mon May 8 09:06:03 PDT 2006
J. McConnell wrote:
> On 5/8/06, Mattias Jiderhamn <mj-lists at expertsystems.se> wrote:
>>
>> As stated above, you've got the same issue when using the generics
>> enabled core Collection API (java.util.*) and also a package
>> depending the Collection API but compiled agains the non generics
>> (pre JDK 1.5) version.
>> The only real difference I can think of betweet these two scenarios
>> is that the Collections API *define* generic classes/interfaces
>> (List<E>) while JDOM would "instantiate" the generic classes
>> (List<Element>).
>> Does anybody know if this would affect the binary compatibility?
>>
>
> I may be mistaken, but I think that we would be fine here because of
> type-erasure. The "List<Element>" syntax is meaninful only at
> compile-time. At runtime, the JVM treats it as a "List<Object>",
> which is exactly what a "List" is treated as.
>
Right. Generics are only some kind of "preprocessor hack". Compatibility
is the reason why Generics in Java were implemented using erasure (and
the reason why Generics are sometimes so annoying ;-) )
If one uses something like the JAD decomplier the decompiled code
doesn't look much different to the code one would write without
Generics. Only now it's the compiler writing the boilerplate code.
Generics is more some kind of a different representation in source which
nicer to use for developers.
Having a JDOM 1.5 which is only enhanced in the way that it uses
Generics should be a drop-in replacement when used with a 1.5 (or later)
runtime.
(Internally it could have some more tweaks, e.g. using "StringBuilder"
instead "StringBuffer" etc. but that's another point.)
Victor
More information about the jdom-interest
mailing list