[cp-patches] [generics] FYI: Fixed compile error in java/util/Collections.java

Andrew John Hughes gnu_andrew at member.fsf.org
Wed Jun 21 18:59:09 UTC 2006

On Wed, 2006-06-21 at 13:39 +0200, Jeroen Frijters wrote:
> Hi,
> Now that builder is using a new version of ecj, the generics branch no
> longer compiled due to a cast bug. I checked in a fix.
> Regards,
> Jeroen
> 2006-06-21  Jeroen Frijters  <jeroen at frijters.net>
>         * java/util/Collections (entrySet): Fixed compile error.

It's a horrible way to fix it, but then most of the things about how
Java has implemented these things is.

For those who don't know, the 'fix' is basically to insert a cast to a
raw type prior to the conversion to Class<Map.Entry<K,V>>.  The result
is that instead of applying a capture conversion (where the parameters
of a type are converted, G<T_1...T_n> to G<S_1...S_n>, which requires
either exact type equality or wildcards - 5.1.10 in the 3rd edition of
the language spec.), we remove the type parameters, creating a raw type.
An unchecked conversion (5.1.9) then converts the raw type back to a
parameterized type, which only results in an unchecked warning.

Raw types are basically legacy versions of types that are now
parameterized (e.g. List as opposed to List<T>) and are required so that
every Java program doesn't break with the new type system.

The problem with how generics are implemented is that they are fine when
we are just showing people nice examples like 'oooh, you can get things
from your list without having to cast' but are soon as you get to any
point where the things have to interact with stuff that isn't typed that
way, things go mad.  This happens all over the Java API, and especially
in the collections classes.  The problems arise from bending over
backwards to support Java 1.4 and below, and IMO, they pretty much ruin
the advantages of having a more advanced type system.  

Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint)
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor

"Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn."
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
public class gcj extends Freedom implements Java { ... }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://developer.classpath.org/pipermail/classpath-patches/attachments/20060621/7d6ab7fd/attachment.pgp

More information about the Classpath-patches mailing list