mcimadamore@1415: /* mcimadamore@1415: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. mcimadamore@1415: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@1415: * mcimadamore@1415: * This code is free software; you can redistribute it and/or modify it mcimadamore@1415: * under the terms of the GNU General Public License version 2 only, as mcimadamore@1415: * published by the Free Software Foundation. mcimadamore@1415: * mcimadamore@1415: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@1415: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@1415: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@1415: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@1415: * accompanied this code). mcimadamore@1415: * mcimadamore@1415: * You should have received a copy of the GNU General Public License version mcimadamore@1415: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@1415: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@1415: * mcimadamore@1415: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mcimadamore@1415: * or visit www.oracle.com if you need additional information or have any mcimadamore@1415: * questions. mcimadamore@1415: */ mcimadamore@1415: mcimadamore@1415: /** mcimadamore@1415: * @test mcimadamore@1415: * @bug 8003280 mcimadamore@1415: * @summary Add lambda tests mcimadamore@1415: * This test is for overloaded methods, verify that the specific method is mcimadamore@1415: selected when type inference occurs mcimadamore@1415: * @compile InferenceTest5.java mcimadamore@1415: * @run main InferenceTest5 mcimadamore@1415: */ mcimadamore@1415: mcimadamore@1415: import java.util.List; mcimadamore@1415: import java.io.File; mcimadamore@1415: mcimadamore@1415: public class InferenceTest5 { mcimadamore@1415: mcimadamore@1415: private static void assertTrue(boolean b) { mcimadamore@1415: if(!b) mcimadamore@1415: throw new AssertionError(); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: public static void main(String[] args) { mcimadamore@1415: InferenceTest5 test = new InferenceTest5(); mcimadamore@1415: int n = test.method1((a, b) -> {} ); mcimadamore@1415: assertTrue(n == 1); mcimadamore@1415: mcimadamore@1415: n = test.method1(() -> null); mcimadamore@1415: assertTrue(n == 2); mcimadamore@1415: mcimadamore@1415: n = test.method1(a -> null); mcimadamore@1415: assertTrue(n == 3); mcimadamore@1415: mcimadamore@1415: n = test.method1(a -> {}); mcimadamore@1415: assertTrue(n == 4); mcimadamore@1415: mcimadamore@1415: n = test.method1(() -> {}); mcimadamore@1415: assertTrue(n == 5); mcimadamore@1415: mcimadamore@1415: n = test.method1((a, b) -> 0); mcimadamore@1415: assertTrue(n == 6); mcimadamore@1415: mcimadamore@1415: n = test.method1((a, b) -> null); mcimadamore@1415: assertTrue(n == 6); mcimadamore@1415: mcimadamore@1415: n = test.method1((a, b) -> null, (a, b) -> null); mcimadamore@1415: assertTrue(n == 7); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM1 s) { mcimadamore@1415: return 1; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM2 s) { mcimadamore@1415: return 2; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM3 s) { mcimadamore@1415: return 3; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM4 s) { mcimadamore@1415: return 4; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM5 s) { mcimadamore@1415: return 5; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM6 s) { mcimadamore@1415: return 6; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: int method1(SAM6... s) { mcimadamore@1415: return 7; mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: static interface SAM1 { mcimadamore@1415: void foo(List a, List b); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: static interface SAM2 { mcimadamore@1415: List foo(); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: static interface SAM3 { mcimadamore@1415: String foo(int a); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: static interface SAM4 { mcimadamore@1415: void foo(List a); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: static interface SAM5 { mcimadamore@1415: void foo(); mcimadamore@1415: } mcimadamore@1415: mcimadamore@1415: static interface SAM6 { mcimadamore@1415: V get(T t, T t2); mcimadamore@1415: } mcimadamore@1415: }