<Swing Dev> [PATCH] 6179357-related: Working on warnings removal

Roman Kennke roman.kennke at aicas.com
Tue Oct 16 19:55:14 UTC 2007


Hi Ismael,

> Roman Kennke <roman at ...> writes:
> > This isn't exactly correct. The equivalent of a ReferenceQueue in
> > generics notation is ReferenceQueue<?>. See: 
> 
> I don't think there's an exact equivalent, but if you take a List as an example
> (because it has public methods that accept the generic argument), the following
> will not compile:
> 
>   List<?> list = new ArrayList<Object>();
>   list.add("22"); // compile error
>   list.add(new Object()); // compile error

Ok, I see. Generics can be really confusing...

> But if declare it as List<Object>, it will compile fine. So I would say that
> declaring it with the Object generic argument is closer to the raw type.
> However, there are still differences because the following doesn't work:
> 
>   List<Object> list = new ArrayList<Object>();
>   list = new ArrayList<String>();
> 
> While List<?> would work. Now, you may be wondering why I used a List instead of
> a ReferenceQueue in my example. It's because the enqueue method in
> ReferenceQueue isn't public. As such, it doesn't really make much of a
> difference how you declare it since you will get an Object out of the queue with
> both declarations.

Please ignore my amateurish commen then ;-) Thanks for cleaning up. One
day I hopefully will grok generics in their full glory...

/Roman

-- 
Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-0
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt




More information about the swing-dev mailing list