|
1 /* |
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import java.io.Serializable; |
|
25 import java.util.Calendar; |
|
26 |
|
27 /** |
|
28 * @test |
|
29 * @bug 8003280 |
|
30 * @summary Add lambda tests |
|
31 * This test is for when lambda return type is inferred from target type |
|
32 * @compile InferenceTest789.java |
|
33 * @run main InferenceTest789 |
|
34 */ |
|
35 |
|
36 public class InferenceTest789 { |
|
37 |
|
38 private static void assertTrue(boolean b) { |
|
39 if(!b) |
|
40 throw new AssertionError(); |
|
41 } |
|
42 |
|
43 public static void main(String[] args) { |
|
44 InferenceTest789 test = new InferenceTest789(); |
|
45 test.method1(() -> 1); |
|
46 SAM1<? extends Number> sam1 = () -> 1.0; |
|
47 SAM1<? extends Serializable> sam1_2 = () -> "a"; |
|
48 SAM1<? extends Comparable<?>> sam1_3 = () -> Calendar.getInstance(); |
|
49 SAM1<?> sam1_4 = () -> 1.5f; |
|
50 |
|
51 SAM2<Number> sam2 = a -> 1; |
|
52 SAM2<? extends Serializable> sam2_2 = a -> 1; |
|
53 } |
|
54 |
|
55 void method1(SAM1<?> s) { |
|
56 System.out.println("s.m1()=" + s.m1() + " s.m1().getClass()=" + s.m1().getClass()); |
|
57 assertTrue(s.m1().equals(new Integer(1))); |
|
58 } |
|
59 |
|
60 interface SAM1<T> { |
|
61 T m1(); |
|
62 } |
|
63 |
|
64 interface SAM2<T extends Serializable> { |
|
65 T m2(T t); |
|
66 } |
|
67 } |