Tue, 18 Dec 2012 22:16:45 +0000
8005193: New regression test test/tools/javac/lambda/BadMethodCall2.java fails
Summary: Bad golden file in negative test
Reviewed-by: jjh
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 */
24 /**
25 * @test
26 * @bug 8003280
27 * @summary Add lambda tests
28 * Test that the most specific reference is selected when method parameters are elided
29 * @compile MethodRef6.java
30 * @run main MethodRef6
31 */
33 public class MethodRef6 {
35 static interface A { String make(Integer i); }
37 static interface B { String make(Number i); }
39 private static void assertTrue(boolean cond) {
40 if (!cond)
41 throw new AssertionError();
42 }
44 static String m(Object o) {
45 return "Object " + o;
46 }
48 static String m(Number n) {
49 return "Number " + n;
50 }
52 static String m(Integer i) {
53 return "Integer " + i;
54 }
56 static String m(int i) {
57 return "int " + i;
58 }
60 public static void main(String[] args) {
61 A a = MethodRef6::m;
62 assertTrue(a.make(1).equals("Integer 1"));//method parameter type inferred from SAM descriptor, boxing applied
63 B b = MethodRef6::m;
64 assertTrue(b.make(1).equals("Number 1"));//method parameter type inferred from SAM descriptor, boxing and widen applied
65 }
66 }