United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6559172 : Unchecked warning required for checked assignment

Details
Type:
Enhancement
Submit Date:
2007-05-18
Status:
Closed
Updated Date:
2011-12-22
Project Name:
JDK
Resolved Date:
2007-05-29
Component:
specification
OS:
generic
Sub-Component:
language
CPU:
generic
Priority:
P5
Resolution:
Won't Fix
Affected Versions:
5.0
Fixed Versions:

Related Reports
Relates:

Sub Tasks

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

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
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



Hardware and Software, Engineered to Work Together