G
gbmvdd
Is anyone else disappointed with the approach that Java 1.5 has taken
to generic programming? I prefer Java's maturity and openness compared
to C#, but the generic types offered by .NET 2 seem vastly superior to
those offered by Java 1.5. It seems to me that by using erasures, javac
takes all the useful information you've given about the types your code
will use and throws it away. I think having to add the @unchecked
annotation is clunky, and more importantly the compiler is also missing
out on the opportunity to optimise by removing boxing and casts in
collection-related code.
With this in mind, I began to wonder whether Java 1.5 source code could
be compiled in a way similar to .NET 2, so as to be able to take
advantage of the benefits of the latter's approach. I found a paper by
Boris Bokowski and Markus Dahm called "Poor Man's Genericity", but no
remaining Web presence. Can anyone tell me what became of this? Perhaps
it would be possible and useful to adapt it to conform to Java 1.5
syntax.
I suppose the main semantic difference you would get is that
List<int>.class == List<bool>.class in Java 1.5, but that's not the
case if you generate your specialised classes at run-time. To my mind
you actually wouldn't want above expression to be true anyway. Maybe
I've been writing too much C++, so can anyone give me an example where
it's helpful that the types compare equal? Am I missing something, or
is "Poor Man's Genericity" in fact much richer than the genericity Java
has to offer today?
George
to generic programming? I prefer Java's maturity and openness compared
to C#, but the generic types offered by .NET 2 seem vastly superior to
those offered by Java 1.5. It seems to me that by using erasures, javac
takes all the useful information you've given about the types your code
will use and throws it away. I think having to add the @unchecked
annotation is clunky, and more importantly the compiler is also missing
out on the opportunity to optimise by removing boxing and casts in
collection-related code.
With this in mind, I began to wonder whether Java 1.5 source code could
be compiled in a way similar to .NET 2, so as to be able to take
advantage of the benefits of the latter's approach. I found a paper by
Boris Bokowski and Markus Dahm called "Poor Man's Genericity", but no
remaining Web presence. Can anyone tell me what became of this? Perhaps
it would be possible and useful to adapt it to conform to Java 1.5
syntax.
I suppose the main semantic difference you would get is that
List<int>.class == List<bool>.class in Java 1.5, but that's not the
case if you generate your specialised classes at run-time. To my mind
you actually wouldn't want above expression to be true anyway. Maybe
I've been writing too much C++, so can anyone give me an example where
it's helpful that the types compare equal? Am I missing something, or
is "Poor Man's Genericity" in fact much richer than the genericity Java
has to offer today?
George