test/tools/javac/lambda/methodReference/MethodRef_neg.java

changeset 1415
01c9d4161882
parent 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/methodReference/MethodRef_neg.java	Sat Nov 17 19:01:03 2012 +0000
     1.3 @@ -0,0 +1,36 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *   This is negative test for wrong parameter/return type in method references
     1.9 + * @compile/fail/ref=MethodRef_neg.out -XDrawDiagnostics MethodRef_neg.java
    1.10 + */
    1.11 +
    1.12 +public class MethodRef_neg {
    1.13 +
    1.14 +    static interface A {void m(Integer i);}
    1.15 +
    1.16 +    static interface B {void m(String s);}
    1.17 +
    1.18 +    static interface C {Integer m();}
    1.19 +
    1.20 +    static interface D {String m();}
    1.21 +
    1.22 +
    1.23 +    static void bar(int x) { }
    1.24 +
    1.25 +    int foo() {
    1.26 +        return 5;
    1.27 +    }
    1.28 +
    1.29 +    static void make() { }
    1.30 +
    1.31 +    void method() {
    1.32 +        A a = MethodRef_neg::bar; //boxing on parameter type is ok
    1.33 +        B b = MethodRef_neg::bar; //wrong parameter type, required: String, actual: int
    1.34 +        C c = this::foo; //boxing on return type is ok
    1.35 +        D d = this::foo; //wrong return type, required: String, actual: int
    1.36 +        a = MethodRef_neg::make; //missing parameter
    1.37 +        c = MethodRef_neg::make; //missing return type
    1.38 +    }
    1.39 +}

mercurial