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

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

mercurial