test/tools/javac/lambda/MethodReference43.java

changeset 2000
4a6acc42c3a1
parent 1510
7873d37f5b37
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 diamond inference is applied when using raw constructor reference qualifier 28 * check that diamond inference is applied when using raw constructor reference qualifier
29 * @run main MethodReference43 29 * @compile/fail/ref=MethodReference43.out -XDrawDiagnostics MethodReference43.java
30 */ 30 */
31 public class MethodReference43 { 31 public class MethodReference43 {
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 Foo<?> m(String s); 34 Foo<?> m(String s);
43 } 35 }
44 36
56 48
57 static class Foo<X extends Number> { 49 static class Foo<X extends Number> {
58 Foo(X x) { } 50 Foo(X x) { }
59 } 51 }
60 52
53 static void m1(SAM1 s) { }
61 54
62 static void m(SAM1 s) { assertTrue(false); } 55 static void m2(SAM2 s) { }
63 static void m(SAM2 s) { assertTrue(false); } 56
64 static void m(SAM3 s) { assertTrue(false); } 57 static void m3(SAM3 s) { }
65 static void m(SAM4 s) { assertTrue(true); } 58
59 static void m4(SAM4 s) { }
60
61 static void m5(SAM1 s) { }
62 static void m5(SAM2 s) { }
63 static void m5(SAM3 s) { }
64 static void m5(SAM4 s) { }
66 65
67 public static void main(String[] args) { 66 public static void main(String[] args) {
68 m(Foo::new); 67 m1(Foo::new);
69 assertTrue(assertionCount == 1); 68 m2(Foo::new);
69 m3(Foo::new);
70 m4(Foo::new);
71 m5(Foo::new);
70 } 72 }
71 } 73 }

mercurial