langtools/test/tools/javac/CaptureInSubtype.java
author jlahoda
Tue, 16 Aug 2016 16:43:00 +0200
changeset 40504 0a01f6710c84
parent 37636 6c6e6e25189d
permissions -rw-r--r--
8078561: Error message should be generated once when -source 6 is specified Summary: Code to avoid duplicated errors about features not supported in the current source level moved to Log Reviewed-by: jjg
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 {
37636
6c6e6e25189d 8154504: javac tests fail after JDK API is deprecated
jjg
parents: 24796
diff changeset
    36
        static Flaw<Number> fn =  new Flaw<Number>(Integer.valueOf(3));
10
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
}