langtools/test/tools/javac/generics/diamond/pos/Pos03.java
author mcimadamore
Mon, 07 Mar 2011 14:31:50 +0000
changeset 8635 383a416a2bdf
parent 5520 86e4b9a9da40
child 29776 984a79b71cfe
permissions -rw-r--r--
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes Summary: Disallow diamond on anonymous innner class creation expression (as per JSR 334's EDR) Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     1
/*
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     4
 *
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     8
 *
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    14
 *
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5327
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5327
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5327
diff changeset
    21
 * questions.
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    22
 */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    23
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    24
/*
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    25
 * @test
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    26
 * @bug 6939620 7020044
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    27
 *
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    28
 * @summary  basic test for diamond (simple/qualified type-expressions, member inner)
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    29
 * @author mcimadamore
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    30
 * @compile Pos03.java
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    31
 * @run main Pos03
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    32
 *
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    33
 */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    34
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    35
public class Pos03<U> {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    36
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    37
    class Foo<V> {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    38
        Foo(V x) {}
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    39
        <Z> Foo(V x, Z z) {}
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    40
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    41
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    42
    void testSimple() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    43
        Foo<Integer> f1 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    44
        Foo<? extends Integer> f2 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    45
        Foo<?> f3 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    46
        Foo<? super Integer> f4 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    47
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    48
        Foo<Integer> f5 = new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    49
        Foo<? extends Integer> f6 = new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    50
        Foo<?> f7 = new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    51
        Foo<? super Integer> f8 = new Foo<>(1, "");
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    52
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    53
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    54
    void testQualified_1() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    55
        Foo<Integer> f1 = new Pos03<U>.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    56
        Foo<? extends Integer> f2 = new Pos03<U>.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    57
        Foo<?> f3 = new Pos03<U>.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    58
        Foo<? super Integer> f4 = new Pos03<U>.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    59
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    60
        Foo<Integer> f5 = new Pos03<U>.Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    61
        Foo<? extends Integer> f6 = new Pos03<U>.Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    62
        Foo<?> f7 = new Pos03<U>.Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    63
        Foo<? super Integer> f8 = new Pos03<U>.Foo<>(1, "");
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    64
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    65
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    66
    void testQualified_2(Pos03<U> p) {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    67
        Foo<Integer> f1 = p.new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    68
        Foo<? extends Integer> f2 = p.new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    69
        Foo<?> f3 = p.new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    70
        Foo<? super Integer> f4 = p.new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    71
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    72
        Foo<Integer> f5 = p.new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    73
        Foo<? extends Integer> f6 = p.new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    74
        Foo<?> f7 = p.new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    75
        Foo<? super Integer> f8 = p.new Foo<>(1, "");
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    76
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    77
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    78
    public static void main(String[] args) {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    79
        Pos03<String> p3 = new Pos03<>();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    80
        p3.testSimple();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    81
        p3.testQualified_1();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    82
        p3.testQualified_2(p3);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    83
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    84
}