test/tools/javac/lambda/MostSpecific05.java

changeset 2000
4a6acc42c3a1
parent 1415
01c9d4161882
child 2525
2eb010b6cb22
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 * Structural most specific doesn't handle cases with wildcards in functional interfaces 28 * Structural most specific doesn't handle cases with wildcards in functional interfaces
29 * @compile/fail/ref=MostSpecific05.out -XDrawDiagnostics MostSpecific05.java
29 */ 30 */
30 public class MostSpecific05 { 31 public class MostSpecific05 {
31
32 static int assertionCount = 0;
33
34 static void assertTrue(boolean cond) {
35 assertionCount++;
36 if (!cond)
37 throw new AssertionError();
38 }
39 32
40 interface ObjectConverter<T extends Object> { 33 interface ObjectConverter<T extends Object> {
41 T map(Object o); 34 T map(Object o);
42 } 35 }
43 36
44 interface NumberConverter<T extends Number> { 37 interface NumberConverter<T extends Number> {
45 T map(Object o); 38 T map(Object o);
46 } 39 }
47 40
48 static class MyMapper<A extends Object, B extends Number> { 41 static class MyMapper<A extends Object, B extends Number> {
49 void map(ObjectConverter<? extends A> m) { assertTrue(false); } 42 void map(ObjectConverter<? extends A> m) { }
50 void map(NumberConverter<? extends B> m) { assertTrue(true); } 43 void map(NumberConverter<? extends B> m) { }
51 } 44 }
52 45
53 public static void main(String[] args) { 46 public static void main(String[] args) {
54 MyMapper<Number, Double> mm = new MyMapper<Number, Double>(); 47 MyMapper<Number, Double> mm = new MyMapper<Number, Double>();
55 mm.map(e->1.0); 48 mm.map(e->1.0); //ambiguous - implicit
56 assertTrue(assertionCount == 1); 49 mm.map((Object e)->1.0); //ok
57 } 50 }
58 } 51 }

mercurial