langtools/test/tools/javac/generics/diamond/pos/Pos02.java
author sadayapalam
Mon, 30 Mar 2015 17:09:14 +0530
changeset 29776 984a79b71cfe
parent 8635 383a416a2bdf
permissions -rw-r--r--
8062373: Project Coin: diamond and anonymous classes Summary: Allow diamond inference in combination with anonymous class instance creation Reviewed-by: mcimadamore, vromero Contributed-by: srikanth.adayapalam@oracle.com, maurizio.cimadamore@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
     1
/*
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
     2
 * Copyright (c) 2010, 2015, 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
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    26
 * @bug 6939620 7020044 8062373
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)
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 Pos02.java
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    31
 * @run main Pos02
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
public class Pos02 {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    35
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    36
    static class Foo<X> {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    37
        Foo(X x) {}
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    38
        <Z> Foo(X x, Z z) {}
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    39
    }
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
    void testSimple() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    42
        Foo<Integer> f1 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    43
        Foo<? extends Integer> f2 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    44
        Foo<?> f3 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    45
        Foo<? super Integer> f4 = new Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    46
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    47
        Foo<Integer> f5 = new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    48
        Foo<? extends Integer> f6 = new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    49
        Foo<?> f7 = new Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    50
        Foo<? super Integer> f8 = new Foo<>(1, "");
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    51
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    52
        Foo<Integer> f9 = new Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    53
        Foo<? extends Integer> f10 = new Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    54
        Foo<?> f11 = new Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    55
        Foo<? super Integer> f12 = new Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    56
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    57
        Foo<Integer> f13 = new Foo<>(1, ""){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    58
        Foo<? extends Integer> f14 = new Foo<>(1, ""){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    59
        Foo<?> f15 = new Foo<>(1, ""){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    60
        Foo<? super Integer> f16 = new Foo<>(1, ""){};
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    61
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    62
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    63
    void testQualified() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    64
        Foo<Integer> f1 = new Pos02.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    65
        Foo<? extends Integer> f2 = new Pos02.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    66
        Foo<?> f3 = new Pos02.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    67
        Foo<? super Integer> f4 = new Pos02.Foo<>(1);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    68
8635
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    69
        Foo<Integer> f5 = new Pos02.Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    70
        Foo<? extends Integer> f6 = new Pos02.Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    71
        Foo<?> f7 = new Pos02.Foo<>(1, "");
383a416a2bdf 7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents: 5520
diff changeset
    72
        Foo<? super Integer> f8 = new Pos02.Foo<>(1, "");
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    73
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    74
        Foo<Integer> f9 = new Pos02.Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    75
        Foo<? extends Integer> f10 = new Pos02.Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    76
        Foo<?> f11 = new Pos02.Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    77
        Foo<? super Integer> f12 = new Pos02.Foo<>(1){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    78
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    79
        Foo<Integer> f13 = new Pos02.Foo<>(1, ""){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    80
        Foo<? extends Integer> f14 = new Pos02.Foo<>(1, ""){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    81
        Foo<?> f15 = new Pos02.Foo<>(1, ""){};
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 8635
diff changeset
    82
        Foo<? super Integer> f16 = new Pos02.Foo<>(1, ""){};
5321
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
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    85
    public static void main(String[] args) {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    86
        Pos02 p2 = new Pos02();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    87
        p2.testSimple();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    88
        p2.testQualified();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    89
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
diff changeset
    90
}