test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestSueCase2.java

Tue, 14 May 2013 11:11:09 -0700

author
rfield
date
Tue, 14 May 2013 11:11:09 -0700
changeset 1752
c09b7234cded
parent 1448
7d34e91f66bb
child 2525
2eb010b6cb22
permissions
-rw-r--r--

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

rfield@1422 1 /*
katleman@1448 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
rfield@1422 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
rfield@1422 4 *
rfield@1422 5 * This code is free software; you can redistribute it and/or modify it
rfield@1422 6 * under the terms of the GNU General Public License version 2 only, as
rfield@1422 7 * published by the Free Software Foundation. Oracle designates this
rfield@1422 8 * particular file as subject to the "Classpath" exception as provided
rfield@1422 9 * by Oracle in the LICENSE file that accompanied this code.
rfield@1422 10 *
rfield@1422 11 * This code is distributed in the hope that it will be useful, but WITHOUT
rfield@1422 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
rfield@1422 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
rfield@1422 14 * version 2 for more details (a copy is included in the LICENSE file that
rfield@1422 15 * accompanied this code).
rfield@1422 16 *
rfield@1422 17 * You should have received a copy of the GNU General Public License version
rfield@1422 18 * 2 along with this work; if not, write to the Free Software Foundation,
rfield@1422 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
rfield@1422 20 *
rfield@1422 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
rfield@1422 22 * or visit www.oracle.com if you need additional information or have any
rfield@1422 23 * questions.
rfield@1422 24 */
rfield@1422 25
rfield@1422 26 /**
rfield@1422 27 * @test
rfield@1422 28 * @bug 8003639
rfield@1422 29 * @summary convert lambda testng tests to jtreg and add them
rfield@1422 30 * @run testng MethodReferenceTestSueCase2
rfield@1422 31 */
rfield@1422 32
rfield@1422 33 import org.testng.annotations.Test;
rfield@1422 34
rfield@1422 35 import static org.testng.Assert.assertEquals;
rfield@1422 36
rfield@1422 37 /**
rfield@1422 38 * @author Robert Field
rfield@1422 39 */
rfield@1422 40
rfield@1422 41 @Test
rfield@1422 42 public class MethodReferenceTestSueCase2 {
rfield@1422 43
rfield@1422 44 public interface Sam2<T> { public String get(T target, String s); }
rfield@1422 45
rfield@1422 46 String instanceMethod(String s) { return "2"; }
rfield@1422 47 static Sam2<MethodReferenceTestSueCase2> var = MethodReferenceTestSueCase2::instanceMethod;
rfield@1422 48
rfield@1422 49 String m() { return var.get(new MethodReferenceTestSueCase2(), ""); }
rfield@1422 50
rfield@1422 51 public void testSueCase2() {
rfield@1422 52 assertEquals(m(), "2");
rfield@1422 53 }
rfield@1422 54 }

mercurial