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 | * speculative cache mismatches between Resolve.access and Attr.checkId leads to compiler crashes |
aoqi@0 | 6 | * @compile/fail/ref=ErroneousArg.out -XDrawDiagnostics ErroneousArg.java |
aoqi@0 | 7 | */ |
aoqi@0 | 8 | class ErroneousArg { |
aoqi@0 | 9 | |
aoqi@0 | 10 | private static class Foo { |
aoqi@0 | 11 | static int j() { return 1; } |
aoqi@0 | 12 | } |
aoqi@0 | 13 | |
aoqi@0 | 14 | static Foo foo = new Foo(); |
aoqi@0 | 15 | |
aoqi@0 | 16 | static void m(String s) { } |
aoqi@0 | 17 | static void m(Integer i) { } |
aoqi@0 | 18 | |
aoqi@0 | 19 | static int f(String s) { return 1; } |
aoqi@0 | 20 | |
aoqi@0 | 21 | static int g(String s) { return 1; } |
aoqi@0 | 22 | static int g(Double s) { return 1; } |
aoqi@0 | 23 | |
aoqi@0 | 24 | int h() { return 1; } |
aoqi@0 | 25 | } |
aoqi@0 | 26 | |
aoqi@0 | 27 | class TestErroneousArg extends ErroneousArg { |
aoqi@0 | 28 | static void test() { |
aoqi@0 | 29 | m(unknown()); //method not found |
aoqi@0 | 30 | m(f(1)); //inapplicable method |
aoqi@0 | 31 | m(g(1)); //inapplicable methods |
aoqi@0 | 32 | m(g(null)); //ambiguous |
aoqi@0 | 33 | m(h()); //static error |
aoqi@0 | 34 | m(foo.j()); //inaccessible method |
aoqi@0 | 35 | } |
aoqi@0 | 36 | } |