JDK-6256789 : Legal cast rejected
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-04-18
  • Updated: 2010-04-02
  • Resolved: 2005-08-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Duplicate :  
Description
This program doesn't compile:

import java.lang.ref.*;
 
public class CastProb {
 
  public ExtraRef prob(ReferenceQueue<Object> refQ) {
    return((ExtraRef)refQ.remove());
  }
 
  public static class ExtraRef
    extends WeakReference<Object> {
 
    int extraInfo;
 
    public ExtraRef(Object value) {
      super(value);
    }
  }
}

See http://forum.java.sun.com/thread.jspa?threadID=618527

###@###.### 2005-04-18 19:15:37 GMT

Comments
WORK AROUND Chain the cast: (ExtraRef)(WeakReference) import java.lang.ref.*; public class CastProb { public ExtraRef prob(ReferenceQueue<Object> refQ) throws InterruptedException { return((ExtraRef)(WeakReference)refQ.remove()); } public static class ExtraRef extends WeakReference<Object> { int extraInfo; public ExtraRef(Object value) { super(value); } } } ###@###.### 2005-04-18 19:15:37 GMT
18-04-2005