test/tools/javac/lambda/MethodReference46.java

changeset 2000
4a6acc42c3a1
parent 1415
01c9d4161882
child 2015
a4b9a8859e58
equal deleted inserted replaced
1999:7993cfab8610 2000:4a6acc42c3a1
1 /* 1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
24 /* 24 /*
25 * @test 25 * @test
26 * @bug 8003280 26 * @bug 8003280
27 * @summary Add lambda tests 27 * @summary Add lambda tests
28 * check that generic method reference is inferred when type parameters are omitted 28 * check that generic method reference is inferred when type parameters are omitted
29 * @run main MethodReference46 29 * @compile/fail/ref=MethodReference46.out -XDrawDiagnostics MethodReference46.java
30 */ 30 */
31 public class MethodReference46 { 31 public class MethodReference46 {
32
33 static int assertionCount = 0;
34
35 static void assertTrue(boolean cond) {
36 assertionCount++;
37 if (!cond)
38 throw new AssertionError();
39 }
40 32
41 interface SAM1 { 33 interface SAM1 {
42 void m(String s); 34 void m(String s);
43 } 35 }
44 36
54 Foo(X x) { } 46 Foo(X x) { }
55 } 47 }
56 48
57 static <X extends Number> void m(X fx) { } 49 static <X extends Number> void m(X fx) { }
58 50
59 static void g(SAM1 s) { assertTrue(false); } 51 static void g1(SAM1 s) { }
60 static void g(SAM2 s) { assertTrue(true); } 52
61 static void g(SAM3 s) { assertTrue(false); } 53 static void g2(SAM2 s) { }
54
55 static void g3(SAM3 s) { }
56
57 static void g4(SAM1 s) { }
58 static void g4(SAM2 s) { }
59 static void g4(SAM3 s) { }
62 60
63 public static void main(String[] args) { 61 public static void main(String[] args) {
64 g(MethodReference46::m); 62 g1(MethodReference46::m);
65 assertTrue(assertionCount == 1); 63 g2(MethodReference46::m);
64 g3(MethodReference46::m);
65 g4(MethodReference46::m);
66 } 66 }
67 } 67 }

mercurial