JDK-6559172 : Unchecked warning required for checked assignment
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2007-05-18
  • Updated: 2011-12-22
  • Resolved: 2007-05-29
Related Reports
Relates :  
Description
The program below generates one warning, although the two fields has
equivalent types.

class Handle<E extends Number> {
}

abstract class GenericAssignment {

    Handle<? extends Number> whyWarning = lookup(Handle.class);
    Handle<?> noWarning = lookup(Handle.class);

    abstract <T> T lookup(Class<T> clazz);

}

Comments
EVALUATION I presume the Description means "the two fields have equivalent run-time types". Our "concession to practicality" (JLS 5.1.9) is that no unchecked warning is given when assigning to Handle<?>. But an unchecked warning must be given when the raw Handle returned from lookup is assigned to a Handle<? extends ...>. What else can be done, without reification?
2007-05-29

EVALUATION Although this may seem easy to fix, it can easily become complicated: class Handle<E extends Handle<E>> { } abstract class GenericAssignment { Handle<? extends Handle<?>> whyWarning = lookup(Handle.class); Handle<?> noWarning = lookup(Handle.class); abstract <T> T lookup(Class<T> clazz); }
2007-05-18