|
Duplicate :
|
|
|
Duplicate :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
A DESCRIPTION OF THE REQUEST :
The jls3 states that for a given t of type T,
t.getClass() is typed Class<? extends erasure(T)>.
I think the getClass() typing rule could be changed to
Class<? extends wildcard(T)>
The wildcard operation is defined by:
if T is parametrized, wildcard(T)=erasure(T)<?>
else , wildcard(T)=T
JUSTIFICATION :
1) This rule introduce a raw type.
Raw type must ONLY be used to interact with legacy code.
2) The new Rule introduce a wildcard.
Relationship between parametrized type and wildcard are based
on subtyping rules.
Relationship between parametrized type and wildcard are based
on raw type conversion.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the program must not compile
ACTUAL -
the program compile
---------- BEGIN SOURCE ----------
public void f(ArrayList<Integer> l1, ArrayList<String> l2)
throws InstantiationException, IllegalAccessException {
l1.getClass().newInstance().addAll(l2.getClass().newInstance());
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
public Class<? extends ArrayList<?>> wildcardGetClass(ArrayList<?> list) {
return (Class<? extends ArrayList<?>>)list.getClass();
}
public void f(ArrayList<Integer> l1, ArrayList<String> l2)
throws InstantiationException, IllegalAccessException {
wildcardGetClass(l1).newInstance().addAll(
wildcardGetClass(l2).newInstance());
}
###@###.### 10/26/04 22:47 GMT
|