Tue, 14 May 2013 11:11:09 -0700
8012556: Implement lambda methods on interfaces as static
8006140: Javac NPE compiling Lambda expression on initialization expression of static field in interface
Summary: Lambdas occurring in static contexts or those not needing instance information should be generated into static methods. This has long been the case for classes. However, as a work-around to the lack of support for statics on interfaces, interface lambda methods have been generated into default methods. For lambdas in interface static contexts (fields and static methods) this causes an NPE in javac because there is no 'this'. MethodHandles now support static methods on interfaces. This changeset allows lambda methods to be generated as static interface methods. An existing bug in Hotspot (8013875) is exposed in a test when the "-esa" flag is used. This test and another test that already exposed this bug have been marked with @ignore.
Reviewed-by: mcimadamore
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * @test /nodynamiccopyright/ |
aoqi@0 | 3 | * @bug 8003280 |
aoqi@0 | 4 | * @summary Add lambda tests |
aoqi@0 | 5 | * check that break/continue is disallowed in lambda expressions |
aoqi@0 | 6 | * @author Maurizio Cimadamore |
aoqi@0 | 7 | * @compile/fail/ref=BadBreakContinue.out -XDrawDiagnostics BadBreakContinue.java |
aoqi@0 | 8 | */ |
aoqi@0 | 9 | |
aoqi@0 | 10 | class BadBreakContinue { |
aoqi@0 | 11 | |
aoqi@0 | 12 | static interface SAM { |
aoqi@0 | 13 | void m(); |
aoqi@0 | 14 | } |
aoqi@0 | 15 | |
aoqi@0 | 16 | SAM s1 = ()-> { break; }; |
aoqi@0 | 17 | SAM s2 = ()-> { continue; }; |
aoqi@0 | 18 | SAM s3 = ()-> { |
aoqi@0 | 19 | SAM s3_1 = ()-> { break; }; |
aoqi@0 | 20 | SAM s3_2 = ()-> { continue; }; |
aoqi@0 | 21 | }; |
aoqi@0 | 22 | |
aoqi@0 | 23 | void testLabelled() { |
aoqi@0 | 24 | loop: while (true) { |
aoqi@0 | 25 | SAM s1 = ()-> { break loop; }; |
aoqi@0 | 26 | SAM s2 = ()-> { continue loop; }; |
aoqi@0 | 27 | SAM s3 = ()-> { |
aoqi@0 | 28 | SAM s3_1 = ()-> { break loop; }; |
aoqi@0 | 29 | SAM s3_2 = ()-> { continue loop; }; |
aoqi@0 | 30 | }; |
aoqi@0 | 31 | } |
aoqi@0 | 32 | } |
aoqi@0 | 33 | |
aoqi@0 | 34 | void testNonLabelled() { |
aoqi@0 | 35 | while (true) { |
aoqi@0 | 36 | SAM s1 = ()-> { break; }; |
aoqi@0 | 37 | SAM s2 = ()-> { continue; }; |
aoqi@0 | 38 | SAM s3 = ()-> { |
aoqi@0 | 39 | SAM s3_1 = ()-> { break; }; |
aoqi@0 | 40 | SAM s3_2 = ()-> { continue; }; |
aoqi@0 | 41 | }; |
aoqi@0 | 42 | } |
aoqi@0 | 43 | } |
aoqi@0 | 44 | } |