File: CaptureInSubtype.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 65,320 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
file content (50 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * @test /nodynamiccopyright/
 * @bug 5044626
 * @summary type system loophole in wildcard substitution
 * @author Gilad Bracha
 *
 * @compile/fail/ref=CaptureInSubtype.out -XDrawDiagnostics  CaptureInSubtype.java
 */

import java.util.List;
import java.util.ArrayList;

public class CaptureInSubtype {

    static class SuperOfFlaw<S>{
        S s;
        S get() { return s;}
        void put(S a) { s = a;}

        SuperOfFlaw(S a) { s = a;}
    }

    static class Flaw<T> extends SuperOfFlaw<List<T>> {
        List<T> fetch(){return s;}

        Flaw(T t){super(new ArrayList<T>()); s.add(t);}
    }

    static class SuperOfShowFlaw {

        SuperOfFlaw<List<?>> m(){return null;}
    }


    public static class ShowFlaw extends SuperOfShowFlaw {
        static Flaw<Number> fn =  new Flaw<Number>(Integer.valueOf(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 = ShowFlaw.fn.get().get(0);
    }

}