The equality test has to return true otherwise you would be breaking
compatibility with older code.
This doesn't mean that there aren't other ways to find the "signature"
of map1 and map2.

The Reflection API does provide access to the "specific" types of
generic signatures.

Have a look at this 2005 article:
http://www-128.ibm.com/developerworks/java/library/j-cwt11085.html#h2

The article series uses ASM (DRY) also later on.

On Nov 4, 11:05 pm, Christian Catchpole <[EMAIL PROTECTED]>
wrote:
> Here is my analysis of the situation.  I could be wrong.  But here
> goes..
>
> When I got my copy of Java 5 my first question was, do generics really
> take the cast out of the equation?  I disassembled the code to find
> the cast still exists.  This implies that when you compile this..
>
> HashMap<String,String> map = new HashMap<String,String>()
> String string = map.get("");
>
> The generated code actually equates to this..
>
> HashMap map = new HashMap()
> String string = (String)map.get("");
>
> The class returned by map.getClass() does not know the map only
> contains Strings.  It's actually the reference to the map which
> marshals the types.
>
> I did a quick test...
>
> HashMap<String,String> map1 = new HashMap<String,String>();
> HashMap<Date,Date> map2 = new HashMap<Date,Date>();
>
> System.out.println(map1.getClass() == map2.getClass());
>
> true
>
> They use the same class and can't therefore hold the type information
> for both declarations.
>
> I can only assume this re-compiler the posse were talking about, scans
> the code for the actual cast / type check to determine the types.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to