test/tools/javac/lambda/typeInference/InferenceTest_neg1_2.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /*
     2  * @test /nodynamiccopyright/
     3  * @bug 8003280
     4  * @summary Add lambda tests
     5  *   Overloaded methods take raw SAM types that have type inference according to SAM descriptor
     6              should have ambiguous resolution of method
     7  * @compile/fail/ref=InferenceTest_neg1_2.out -XDrawDiagnostics InferenceTest_neg1_2.java
     8  */
    10 public class InferenceTest_neg1_2 {
    12     public static void main(String[] args) {
    13         InferenceTest_neg1_2 test = new InferenceTest_neg1_2();
    14         test.method(n -> null); //method 1-5 all match
    15         test.method(n -> "a"); //method 2, 4 match
    16         test.method(n -> 0); //method 1, 3, 5 match
    17     }
    19     void method(SAM1 s) { //method 1
    20         Integer i = s.foo("a");
    21     }
    23     void method(SAM2 s) { //method 2
    24         String str = s.foo(0);
    25     }
    27     void method(SAM3<Integer> s) { //method 3
    28         Integer i = s.get(0);
    29     }
    31     void method(SAM4<Double, String> s) { //method 4
    32         String str = s.get(0.0);
    33     }
    35     void method(SAM5<Integer> s) { //method 5
    36         Integer i = s.get(0.0);
    37     }
    39     interface SAM1 {
    40         Integer foo(String a);
    41     }
    43     interface SAM2 {
    44         String foo(Integer a);
    45     }
    47     interface SAM3<T> {
    48         T get(T t);
    49     }
    51     interface SAM4<T, V> {
    52         V get(T t);
    53     }
    55     interface SAM5<T> {
    56         T get(Double i);
    57     }
    58 }

mercurial