test/tools/javac/lambda/MethodReference48.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 raw qualifier in unbound method reference is inferred from descriptor 28 * check that raw qualifier in unbound method reference is inferred from descriptor
29 * @run main MethodReference48 29 * @compile/fail/ref=MethodReference48.out -XDrawDiagnostics MethodReference48.java
30 */ 30 */
31 public class MethodReference48 { 31 public class MethodReference48 {
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 static class Foo<X> { 33 static class Foo<X> {
42 X m() { return null; }; 34 X m() { return null; };
43 } 35 }
44 36
52 44
53 interface SAM3 { 45 interface SAM3 {
54 Object m(Foo<Integer> fi); 46 Object m(Foo<Integer> fi);
55 } 47 }
56 48
57 static void g(SAM1 s) { assertTrue(false); } //return type not compatible 49 static void g1(SAM1 s) { } //return type not compatible
58 static void g(SAM2 s) { assertTrue(true); } //ok 50
59 static void g(SAM3 s) { assertTrue(false); } //ok but less specific 51 static void g2(SAM2 s) { } //ok
52
53 static void g3(SAM3 s) { } //ok
54
55 static void g4(SAM1 s) { } //return type not compatible
56 static void g4(SAM2 s) { } //ok
57 static void g4(SAM3 s) { } //ok
60 58
61 public static void main(String[] args) { 59 public static void main(String[] args) {
62 g(Foo::m); 60 g1(Foo::m);
63 assertTrue(assertionCount == 1); 61 g2(Foo::m);
62 g3(Foo::m);
63 g4(Foo::m);
64 } 64 }
65 } 65 }

mercurial