aoqi@0: /* aoqi@0: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: import java.util.List; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Arrays; aoqi@0: import java.io.Serializable; aoqi@0: import java.io.File; aoqi@0: aoqi@0: /** aoqi@0: * @test aoqi@0: * @bug 8003280 aoqi@0: * @summary Add lambda tests aoqi@0: * Parameter types inferred from target type in generics without wildcard aoqi@0: * @compile InferenceTest2.java aoqi@0: * @run main InferenceTest2 aoqi@0: */ aoqi@0: aoqi@0: public class InferenceTest2 { aoqi@0: aoqi@0: private static void assertTrue(boolean cond) { aoqi@0: if (!cond) aoqi@0: throw new AssertionError(); aoqi@0: } aoqi@0: aoqi@0: public static void main(String[] args) { aoqi@0: aoqi@0: InferenceTest2 test = new InferenceTest2(); aoqi@0: aoqi@0: //test SAM1 aoqi@0: SAM1 sam1 = para -> { String result = ""; aoqi@0: for(String s : para) aoqi@0: if(s.compareTo(result) > 0) aoqi@0: result = s; aoqi@0: return result; }; aoqi@0: List list = Arrays.asList("a", "b", "c"); aoqi@0: assertTrue(sam1.m1(list).equals("c")); aoqi@0: aoqi@0: test.method1(para -> para.get(0)); aoqi@0: aoqi@0: //test SAM2 aoqi@0: SAM2 sam2 = para -> {para = para.substring(0);}; aoqi@0: SAM2 sam2_2 = para -> {}; aoqi@0: SAM2 sam2_3 = para -> { if(para.isDirectory()) aoqi@0: System.out.println("directory"); aoqi@0: }; aoqi@0: aoqi@0: //test SAM3 aoqi@0: SAM3 sam3 = para -> para[0].substring(0, para[0].length()-1); aoqi@0: assertTrue(sam3.m3("hello+").equals("hello")); aoqi@0: aoqi@0: SAM3 sam3_2 = para -> para[0] - para[1]; aoqi@0: assertTrue(sam3_2.m3(1, -1) == 2); aoqi@0: aoqi@0: SAM3 sam3_3 = para -> para[0] + para[1] + para[2] + para[3]; aoqi@0: assertTrue(sam3_3.m3(1.0, 2.0, 3.0, 4.0) == 10.0); aoqi@0: aoqi@0: test.method3(para -> para[0] + 1); aoqi@0: aoqi@0: //test SAM6 aoqi@0: SAM6 sam6 = (para1, para2) -> para1.concat(para2); aoqi@0: assertTrue(sam6.m6("hello", "world").equals("helloworld")); aoqi@0: aoqi@0: test.method6((para1, para2) -> para1 >= para2? para1 : para2); aoqi@0: } aoqi@0: aoqi@0: void method1(SAM1 sam1) { aoqi@0: List list = Arrays.asList(3,2,1); aoqi@0: assertTrue(sam1.m1(list) == 3); aoqi@0: } aoqi@0: aoqi@0: void method3(SAM3 sam3) { aoqi@0: assertTrue(sam3.m3(2.5) == 3.5); aoqi@0: } aoqi@0: aoqi@0: void method6(SAM6 sam6) { aoqi@0: assertTrue(sam6.m6(5L, -5L) == 5); aoqi@0: } aoqi@0: aoqi@0: interface SAM1 { aoqi@0: T m1(List x); aoqi@0: } aoqi@0: aoqi@0: interface SAM2 { aoqi@0: void m2(T x); aoqi@0: } aoqi@0: aoqi@0: interface SAM3 { aoqi@0: T m3(T... x); aoqi@0: } aoqi@0: aoqi@0: interface SAM6 { aoqi@0: T m6(T a, T b); aoqi@0: } aoqi@0: }