Re: Class<T> question

Jeff Kesselman <[email protected]> Wed, 5 Dec 2007 12:03:51 -0500
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Attila Szegedi wrote:
> On 2007.12.05., at 17:25, Gart, Mitchell wrote:
>
>> Thanks, it worked to use Class<?> instead of just Class.
>>
>> In the example you cite, couldn't you have declared
>>
>>   Map<Object, String> map = new HashMap<Object, String>();
>>
>> Instead of
>>
>>   Map<? extends Object, String> map = new HashMap<Object, String>();
>
> Actually, the first form would have been right -- I was typing from
> memory, sorry. I'm not really good with generics yet. I guess I should
> just refrain from giving generics-related advice for now.

Well,  it would work but they dont mean the same thing...

In the first case map is a reference to a map of *anything* mapped to a
string that happens to be holding a ap that maps object to string.

In the second case, it is a reference ONLY to a m,ap that maps object to
string.

Its important to remember that Generics don't respect Java inheritance,
they have their own (more's the pity :( )).

JK

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com