test/tools/javac/generics/diamond/pos/Pos03.java

changeset 383
8109aa93b212
child 543
97b6fa97b8dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/generics/diamond/pos/Pos03.java	Thu Aug 27 13:40:48 2009 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 6840638
     1.7 + *
     1.8 + * @summary  Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
     1.9 + * @author mcimadamore
    1.10 + * @compile Pos03.java -source 1.7
    1.11 + * @run main Pos03
    1.12 + *
    1.13 + */
    1.14 +
    1.15 +public class Pos03<U> {
    1.16 +
    1.17 +    class Foo<V> {
    1.18 +        Foo(V x) {}
    1.19 +        <Z> Foo(V x, Z z) {}
    1.20 +    }
    1.21 +
    1.22 +    void testSimple() {
    1.23 +        Foo<Integer> f1 = new Foo<>(1); //new Foo<Integer> created
    1.24 +        Foo<? extends Integer> f2 = new Foo<>(1); //new Foo<Integer> created
    1.25 +        Foo<?> f3 = new Foo<>(1); //new Foo<Object> created
    1.26 +        Foo<? super Integer> f4 = new Foo<>(1); //new Foo<Object> created
    1.27 +
    1.28 +        Foo<Integer> f5 = new Foo<>(1){}; //new Foo<Integer> created
    1.29 +        Foo<? extends Integer> f6 = new Foo<>(1){}; //new Foo<Integer> created
    1.30 +        Foo<?> f7 = new Foo<>(1){}; //new Foo<Object> created
    1.31 +        Foo<? super Integer> f8 = new Foo<>(1){}; //new Foo<Object> created
    1.32 +
    1.33 +        Foo<Integer> f9 = new Foo<>(1, ""); //new Foo<Integer> created
    1.34 +        Foo<? extends Integer> f10 = new Foo<>(1, ""); //new Foo<Integer> created
    1.35 +        Foo<?> f11 = new Foo<>(1, ""); //new Foo<Object> created
    1.36 +        Foo<? super Integer> f12 = new Foo<>(1, ""); //new Foo<Object> created
    1.37 +
    1.38 +        Foo<Integer> f13 = new Foo<>(1, ""){}; //new Foo<Integer> created
    1.39 +        Foo<? extends Integer> f14 = new Foo<>(1, ""){}; //new Foo<Integer> created
    1.40 +        Foo<?> f15 = new Foo<>(1, ""){}; //new Foo<Object> created
    1.41 +        Foo<? super Integer> f16 = new Foo<>(1, ""){}; //new Foo<Object> created
    1.42 +    }
    1.43 +
    1.44 +    void testQualified_1() {
    1.45 +        Foo<Integer> f1 = new Pos03<U>.Foo<>(1); //new Foo<Integer> created
    1.46 +        Foo<? extends Integer> f2 = new Pos03<U>.Foo<>(1); //new Foo<Integer> created
    1.47 +        Foo<?> f3 = new Pos03<U>.Foo<>(1); //new Foo<Object> created
    1.48 +        Foo<? super Integer> f4 = new Pos03<U>.Foo<>(1); //new Foo<Object> created
    1.49 +
    1.50 +        Foo<Integer> f5 = new Pos03<U>.Foo<>(1){}; //new Foo<Integer> created
    1.51 +        Foo<? extends Integer> f6 = new Pos03<U>.Foo<>(1){}; //new Foo<Integer> created
    1.52 +        Foo<?> f7 = new Pos03<U>.Foo<>(1){}; //new Foo<Object> created
    1.53 +        Foo<? super Integer> f8 = new Pos03<U>.Foo<>(1){}; //new Foo<Object> created
    1.54 +
    1.55 +        Foo<Integer> f9 = new Pos03<U>.Foo<>(1, ""); //new Foo<Integer> created
    1.56 +        Foo<? extends Integer> f10 = new Pos03<U>.Foo<>(1, ""); //new Foo<Integer> created
    1.57 +        Foo<?> f11 = new Pos03<U>.Foo<>(1, ""); //new Foo<Object> created
    1.58 +        Foo<? super Integer> f12 = new Pos03<U>.Foo<>(1, ""); //new Foo<Object> created
    1.59 +
    1.60 +        Foo<Integer> f13 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Integer> created
    1.61 +        Foo<? extends Integer> f14 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Integer> created
    1.62 +        Foo<?> f15 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Object> created
    1.63 +        Foo<? super Integer> f16 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Object> created
    1.64 +    }
    1.65 +
    1.66 +    void testQualified_2(Pos03<U> p) {
    1.67 +        Foo<Integer> f1 = p.new Foo<>(1); //new Foo<Integer> created
    1.68 +        Foo<? extends Integer> f2 = p.new Foo<>(1); //new Foo<Integer> created
    1.69 +        Foo<?> f3 = p.new Foo<>(1); //new Foo<Object> created
    1.70 +        Foo<? super Integer> f4 = p.new Foo<>(1); //new Foo<Object> created
    1.71 +
    1.72 +        Foo<Integer> f5 = p.new Foo<>(1){}; //new Foo<Integer> created
    1.73 +        Foo<? extends Integer> f6 = p.new Foo<>(1){}; //new Foo<Integer> created
    1.74 +        Foo<?> f7 = p.new Foo<>(1){}; //new Foo<Object> created
    1.75 +        Foo<? super Integer> f8 = p.new Foo<>(1){}; //new Foo<Object> created
    1.76 +
    1.77 +        Foo<Integer> f9 = p.new Foo<>(1, ""); //new Foo<Integer> created
    1.78 +        Foo<? extends Integer> f10 = p.new Foo<>(1, ""); //new Foo<Integer> created
    1.79 +        Foo<?> f11 = p.new Foo<>(1, ""); //new Foo<Object> created
    1.80 +        Foo<? super Integer> f12 = p.new Foo<>(1, ""); //new Foo<Object> created
    1.81 +
    1.82 +        Foo<Integer> f13 = p.new Foo<>(1, ""){}; //new Foo<Integer> created
    1.83 +        Foo<? extends Integer> f14 = p.new Foo<>(1, ""){}; //new Foo<Integer> created
    1.84 +        Foo<?> f15 = p.new Foo<>(1, ""){}; //new Foo<Object> created
    1.85 +        Foo<? super Integer> f16 = p.new Foo<>(1, ""){}; //new Foo<Object> created
    1.86 +    }
    1.87 +
    1.88 +    public static void main(String[] args) {
    1.89 +        Pos03<String> p3 = new Pos03<>();
    1.90 +        p3.testSimple();
    1.91 +        p3.testQualified_1();
    1.92 +        p3.testQualified_2(p3);
    1.93 +    }
    1.94 +}

mercurial