test/tools/javac/lambda/TargetType63.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/TargetType63.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,40 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @summary smoke test for inference of throws type variables
     1.7 + * @compile/fail/ref=TargetType63.out -XDrawDiagnostics TargetType63.java
     1.8 + */
     1.9 +class TargetType63 {
    1.10 +
    1.11 +    interface F<T extends Throwable> {
    1.12 +        void m() throws T;
    1.13 +    }
    1.14 +
    1.15 +    void g1() { }
    1.16 +    void g2() throws ClassNotFoundException { }
    1.17 +    void g3() throws Exception { }
    1.18 +
    1.19 +    <Z extends Throwable> void m1(F<Z> fz) throws Z { }
    1.20 +    <Z extends ClassNotFoundException> void m2(F<Z> fz) throws Z { }
    1.21 +
    1.22 +    void test1() {
    1.23 +        m1(()->{ }); //ok (Z = RuntimeException)
    1.24 +        m1(this::g1); //ok (Z = RuntimeException)
    1.25 +    }
    1.26 +
    1.27 +    void test2() {
    1.28 +        m2(()->{ }); //fail (Z = ClassNotFoundException)
    1.29 +        m2(this::g1); //fail (Z = ClassNotFoundException)
    1.30 +    }
    1.31 +
    1.32 +    void test3() {
    1.33 +        m1(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
    1.34 +        m1(this::g2); //fail (Z = ClassNotFoundException)
    1.35 +        m2(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
    1.36 +        m2(this::g2); //fail (Z = ClassNotFoundException)
    1.37 +    }
    1.38 +
    1.39 +    void test4() {
    1.40 +        m1(()->{ throw new Exception(); }); //fail (Z = Exception)
    1.41 +        m1(this::g3); //fail (Z = Exception)
    1.42 +    }
    1.43 +}

mercurial