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

Ismael Juma mlists at juma.me.uk
Tue Oct 16 19:31:18 UTC 2007


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

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.





More information about the swing-dev mailing list