test/runtime/lambda-features/TestInterfaceInit.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 7290
90257dfad6e3
child 8640
d2e8a8cd4166
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

acorn@7290 1 /*
acorn@7290 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
acorn@7290 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
acorn@7290 4 *
acorn@7290 5 * This code is free software; you can redistribute it and/or modify it
acorn@7290 6 * under the terms of the GNU General Public License version 2 only, as
acorn@7290 7 * published by the Free Software Foundation.
acorn@7290 8 *
acorn@7290 9 * This code is distributed in the hope that it will be useful, but WITHOUT
acorn@7290 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
acorn@7290 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
acorn@7290 12 * version 2 for more details (a copy is included in the LICENSE file that
acorn@7290 13 * accompanied this code).
acorn@7290 14 *
acorn@7290 15 * You should have received a copy of the GNU General Public License version
acorn@7290 16 * 2 along with this work; if not, write to the Free Software Foundation,
acorn@7290 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
acorn@7290 18 *
acorn@7290 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
acorn@7290 20 * or visit www.oracle.com if you need additional information or have any
acorn@7290 21 * questions.
acorn@7290 22 *
acorn@7290 23 */
acorn@7290 24
acorn@7290 25 /*
acorn@7290 26 * @test
acorn@7290 27 * @bug 8034275
acorn@7290 28 * @summary [JDK 8u40] Test interface initialization: only for interfaces declaring default methods
acorn@7290 29 * @run main TestInterfaceInit
acorn@7290 30 */
acorn@7290 31 import java.util.List;
acorn@7290 32 import java.util.Arrays;
acorn@7290 33 import java.util.ArrayList;
acorn@7290 34
acorn@7290 35 public class TestInterfaceInit {
acorn@7290 36
acorn@7290 37 static List<Class<?>> cInitOrder = new ArrayList<>();
acorn@7290 38
acorn@7290 39 // Declares a default method and initializes
acorn@7290 40 interface I {
acorn@7290 41 boolean v = TestInterfaceInit.out(I.class);
acorn@7290 42 default void x() {}
acorn@7290 43 }
acorn@7290 44
acorn@7290 45 // Declares a default method and initializes
acorn@7290 46 interface J extends I {
acorn@7290 47 boolean v = TestInterfaceInit.out(J.class);
acorn@7290 48 default void x() {}
acorn@7290 49 }
acorn@7290 50 // No default method, does not initialize
acorn@7290 51 interface JN extends J {
acorn@7290 52 boolean v = TestInterfaceInit.out(JN.class);
acorn@7290 53 }
acorn@7290 54
acorn@7290 55 // Declares a default method and initializes
acorn@7290 56 interface K extends I {
acorn@7290 57 boolean v = TestInterfaceInit.out(K.class);
acorn@7290 58 default void x() {}
acorn@7290 59 }
acorn@7290 60
acorn@7290 61 // No default method, does not initialize
acorn@7290 62 interface KN extends K {
acorn@7290 63 boolean v = TestInterfaceInit.out(KN.class);
acorn@7290 64 }
acorn@7290 65
acorn@7290 66 interface L extends JN, KN {
acorn@7290 67 boolean v = TestInterfaceInit.out(L.class);
acorn@7290 68 default void x() {}
acorn@7290 69 }
acorn@7290 70
acorn@7290 71 public static void main(String[] args) {
acorn@7290 72 // Trigger initialization
acorn@7290 73 boolean v = L.v;
acorn@7290 74
acorn@7290 75 List<Class<?>> expectedCInitOrder = Arrays.asList(I.class,J.class,K.class,L.class);
acorn@7290 76 if (!cInitOrder.equals(expectedCInitOrder)) {
acorn@7290 77 throw new RuntimeException(String.format("Class initialization array %s not equal to expected array %s", cInitOrder, expectedCInitOrder));
acorn@7290 78 }
acorn@7290 79 }
acorn@7290 80
acorn@7290 81 static boolean out(Class c) {
acorn@7290 82 System.out.println("#: initializing " + c.getName());
acorn@7290 83 cInitOrder.add(c);
acorn@7290 84 return true;
acorn@7290 85 }
acorn@7290 86
acorn@7290 87 }

mercurial