United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4773346 generics: generics signature improvement for ReferenceQueue
JDK-4773346 : generics: generics signature improvement for ReferenceQueue

Details
Type:
Enhancement
Submit Date:
2002-11-04
Status:
Closed
Updated Date:
2003-09-04
Project Name:
JDK
Resolved Date:
2003-09-04
Component:
specification
OS:
solaris_8
Sub-Component:
language
CPU:
generic
Priority:
P4
Resolution:
Not an Issue
Affected Versions:
5.0
Fixed Versions:

Related Reports

Sub Tasks

Description
I'm posting this bug to forward a good question (and suggestion) from 
the developer forum for JSR14.

- ###@###.###


in <http://forum.java.sun.com/thread.jsp?forum=316&thread=318549>
http://forum.java.sun.com/profile.jsp?user=241323 writes:

 I want a ReferenceQueue into which I place only WeakReference<MyClass> objects, and from which I can poll WeakReference<MyClass> objects without casts or warnings.

I haven't been able to find any documentation on the genericised version of ReferenceQueue, and am going solely on error messages from the compiler. However, it appears that this class has public signature

public class ReferenceQueue<T>
{
Reference<T> poll();
Reference<T> remove();
Reference<T> remove(long timeout);
}

Why? This doesn't seem very logical to me, and is forcing me to put in casts. Is there any good reason why it is not as follows?

public class ReferenceQueue<R extends Reference>
{
R poll();
R remove();
R remove(long timeout);
}

If not, is there any possibility that it would be altered thus before 1.5?

                                    

Comments
EVALUATION

Declare a ReferenceQueue<X>, and poll() will return a Reference<? extends X>.

If you need your own queue for placing your references into, don't use a ReferenceQueue.  There are many useful collections in java.util and new ones coming as part of JSR 166.

###@###.### 2003-09-03
                                     
2003-09-03



Hardware and Software, Engineered to Work Together