author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 24796 | f940af3221e2 |
child 37636 | 6c6e6e25189d |
permissions | -rw-r--r-- |
10 | 1 |
/* |
24796
f940af3221e2
8044064: Group 1: create .out files for cast and capture negative tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
2 |
* @test /nodynamiccopyright/ |
f940af3221e2
8044064: Group 1: create .out files for cast and capture negative tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
3 |
* @bug 5044626 |
10 | 4 |
* @summary type system loophole in wildcard substitution |
5 |
* @author Gilad Bracha |
|
6 |
* |
|
24796
f940af3221e2
8044064: Group 1: create .out files for cast and capture negative tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
7 |
* @compile/fail/ref=CaptureInSubtype.out -XDrawDiagnostics CaptureInSubtype.java |
10 | 8 |
*/ |
9 |
||
10 |
import java.util.List; |
|
11 |
import java.util.ArrayList; |
|
12 |
||
13 |
public class CaptureInSubtype { |
|
14 |
||
15 |
static class SuperOfFlaw<S>{ |
|
16 |
S s; |
|
17 |
S get() { return s;} |
|
18 |
void put(S a) { s = a;} |
|
19 |
||
20 |
SuperOfFlaw(S a) { s = a;} |
|
21 |
} |
|
22 |
||
23 |
static class Flaw<T> extends SuperOfFlaw<List<T>> { |
|
24 |
List<T> fetch(){return s;} |
|
25 |
||
26 |
Flaw(T t){super(new ArrayList<T>()); s.add(t);} |
|
27 |
} |
|
28 |
||
29 |
static class SuperOfShowFlaw { |
|
30 |
||
31 |
SuperOfFlaw<List<?>> m(){return null;} |
|
32 |
} |
|
33 |
||
34 |
||
35 |
public static class ShowFlaw extends SuperOfShowFlaw { |
|
36 |
static Flaw<Number> fn = new Flaw<Number>(new Integer(3)); |
|
37 |
||
38 |
Flaw<?> m(){return fn;} |
|
39 |
} |
|
40 |
||
41 |
public static void main(String[] args) { |
|
42 |
SuperOfShowFlaw sosf = new ShowFlaw(); |
|
43 |
SuperOfFlaw<List<?>> sof = sosf.m(); |
|
44 |
List<String> ls = new ArrayList<String>(); |
|
45 |
ls.add("Smalltalk rules!"); |
|
46 |
sof.put(ls); |
|
47 |
Number n = ShowFlaw.fn.get().get(0); |
|
48 |
} |
|
49 |
||
50 |
} |