-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
None
-
rc
-
generic
-
solaris_8
The following program - due to Gilad Bracha - illustrates a loophole in the
current specification for generics when wilcards are used. This problem
and its solution are discussed in Viroli and Igarashi's papers, but we
haven't yet incorporated a solution to the problem into the specification or
its reference implementation.
//////////////////////////////////////////////////////////
import java.util.*;
class SuperOfFlaw<S>{
S s;
S get() { return s;}
void put(S a) { s = a;}
SuperOfFlaw(S a) { s = a;}
}
class Flaw<T> extends SuperOfFlaw<List<T>> {
List<T> fetch(){return s;}
Flaw(T t){super(new ArrayList<T>()); s.add(t);}
}
class SuperOfShowFlaw {
SuperOfFlaw<List<?>> m(){return null;}
}
public class ShowFlaw extends SuperOfShowFlaw {
static Flaw<Number> fn = new Flaw<Number>(new Integer(3));
Flaw<?> m(){return fn;}
public static void main(String[] args) {
SuperOfShowFlaw sosf = new ShowFlaw();
SuperOfFlaw<List<?>> sof = sosf.m();
List<String> ls = new ArrayList<String>();
ls.add("Smalltalk rules!");
sof.put(ls);
Number n = fn.get().get(0);
}
}
current specification for generics when wilcards are used. This problem
and its solution are discussed in Viroli and Igarashi's papers, but we
haven't yet incorporated a solution to the problem into the specification or
its reference implementation.
//////////////////////////////////////////////////////////
import java.util.*;
class SuperOfFlaw<S>{
S s;
S get() { return s;}
void put(S a) { s = a;}
SuperOfFlaw(S a) { s = a;}
}
class Flaw<T> extends SuperOfFlaw<List<T>> {
List<T> fetch(){return s;}
Flaw(T t){super(new ArrayList<T>()); s.add(t);}
}
class SuperOfShowFlaw {
SuperOfFlaw<List<?>> m(){return null;}
}
public class ShowFlaw extends SuperOfShowFlaw {
static Flaw<Number> fn = new Flaw<Number>(new Integer(3));
Flaw<?> m(){return fn;}
public static void main(String[] args) {
SuperOfShowFlaw sosf = new ShowFlaw();
SuperOfFlaw<List<?>> sof = sosf.m();
List<String> ls = new ArrayList<String>();
ls.add("Smalltalk rules!");
sof.put(ls);
Number n = fn.get().get(0);
}
}
- relates to
-
JDK-5044626 type system loophole in wildcard substitution
-
- Resolved
-