test/tools/javac/lambda/TargetType63.java

Tue, 13 May 2014 16:11:43 +0100

author
vromero
date
Tue, 13 May 2014 16:11:43 +0100
changeset 2391
8e7bd4c50fd1
parent 0
959103a6100f
permissions
-rw-r--r--

8028503: javac, for method references a primitive type can be added as a bound
Reviewed-by: jjg, dlsmith

aoqi@0 1 /*
aoqi@0 2 * @test /nodynamiccopyright/
aoqi@0 3 * @summary smoke test for inference of throws type variables
aoqi@0 4 * @compile/fail/ref=TargetType63.out -XDrawDiagnostics TargetType63.java
aoqi@0 5 */
aoqi@0 6 class TargetType63 {
aoqi@0 7
aoqi@0 8 interface F<T extends Throwable> {
aoqi@0 9 void m() throws T;
aoqi@0 10 }
aoqi@0 11
aoqi@0 12 void g1() { }
aoqi@0 13 void g2() throws ClassNotFoundException { }
aoqi@0 14 void g3() throws Exception { }
aoqi@0 15
aoqi@0 16 <Z extends Throwable> void m1(F<Z> fz) throws Z { }
aoqi@0 17 <Z extends ClassNotFoundException> void m2(F<Z> fz) throws Z { }
aoqi@0 18
aoqi@0 19 void test1() {
aoqi@0 20 m1(()->{ }); //ok (Z = RuntimeException)
aoqi@0 21 m1(this::g1); //ok (Z = RuntimeException)
aoqi@0 22 }
aoqi@0 23
aoqi@0 24 void test2() {
aoqi@0 25 m2(()->{ }); //fail (Z = ClassNotFoundException)
aoqi@0 26 m2(this::g1); //fail (Z = ClassNotFoundException)
aoqi@0 27 }
aoqi@0 28
aoqi@0 29 void test3() {
aoqi@0 30 m1(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
aoqi@0 31 m1(this::g2); //fail (Z = ClassNotFoundException)
aoqi@0 32 m2(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
aoqi@0 33 m2(this::g2); //fail (Z = ClassNotFoundException)
aoqi@0 34 }
aoqi@0 35
aoqi@0 36 void test4() {
aoqi@0 37 m1(()->{ throw new Exception(); }); //fail (Z = Exception)
aoqi@0 38 m1(this::g3); //fail (Z = Exception)
aoqi@0 39 }
aoqi@0 40 }

mercurial