langtools/test/tools/javac/CaptureInSubtype.java
author lana
Thu, 21 Jan 2016 09:46:01 -0800
changeset 35340 38f7386ed942
parent 24796 f940af3221e2
child 37636 6c6e6e25189d
permissions -rw-r--r--
Added tag jdk-9+102 for changeset 7e3feb2ba5b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     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
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary type system loophole in wildcard substitution
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * @author Gilad Bracha
06bc494ca11e Initial load
duke
parents:
diff changeset
     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
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
import java.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
import java.util.ArrayList;
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
public class CaptureInSubtype {
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
    static class SuperOfFlaw<S>{
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        S s;
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
        S get() { return s;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
        void put(S a) { s = a;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
        SuperOfFlaw(S a) { s = a;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
    static class Flaw<T> extends SuperOfFlaw<List<T>> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
        List<T> fetch(){return s;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        Flaw(T t){super(new ArrayList<T>()); s.add(t);}
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
    static class SuperOfShowFlaw {
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
        SuperOfFlaw<List<?>> m(){return null;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
    public static class ShowFlaw extends SuperOfShowFlaw {
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
        static Flaw<Number> fn =  new Flaw<Number>(new Integer(3));
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
        Flaw<?> m(){return fn;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        SuperOfShowFlaw sosf = new ShowFlaw();
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        SuperOfFlaw<List<?>> sof = sosf.m();
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
        List<String> ls = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
        ls.add("Smalltalk rules!");
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
        sof.put(ls);
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        Number n = ShowFlaw.fn.get().get(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
}