hotspot/test/runtime/lambda-features/TestInterfaceOrder.java
changeset 27402 5c4675ddc00c
child 41705 332239c052cc
equal deleted inserted replaced
27400:c5955f4b7c84 27402:5c4675ddc00c
       
     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  */
       
    24 
       
    25 /*
       
    26  * @test
       
    27  * @bug 8034275
       
    28  * @summary [JDK 8u40] Test interface initialization order
       
    29  * @run main TestInterfaceOrder
       
    30  */
       
    31 
       
    32 import java.util.List;
       
    33 import java.util.Arrays;
       
    34 import java.util.ArrayList;
       
    35 
       
    36 public class TestInterfaceOrder {
       
    37   static List<Class<?>> cInitOrder = new ArrayList<>();
       
    38 
       
    39   public static void main(java.lang.String[] args) {
       
    40     //Trigger initialization
       
    41     C c = new C();
       
    42 
       
    43     List<Class<?>> expectedCInitOrder = Arrays.asList(I.class, J.class, A.class, K.class, B.class, L.class, C.class);
       
    44     if (!cInitOrder.equals(expectedCInitOrder)) {
       
    45       throw new RuntimeException(String.format("Class initialization order %s not equal to expected order %s", cInitOrder, expectedCInitOrder));
       
    46     }
       
    47   }
       
    48 
       
    49   interface I {
       
    50     boolean v = TestInterfaceOrder.out(I.class);
       
    51    default void i() {}
       
    52   }
       
    53 
       
    54   interface J extends I {
       
    55     boolean v = TestInterfaceOrder.out(J.class);
       
    56     default void j() {}
       
    57   }
       
    58 
       
    59   static class A implements J {
       
    60     static boolean v = TestInterfaceOrder.out(A.class);
       
    61   }
       
    62 
       
    63   interface K extends I {
       
    64     boolean v = TestInterfaceOrder.out(K.class);
       
    65     default void k() {}
       
    66   }
       
    67 
       
    68   static class B extends A implements K {
       
    69     static boolean v = TestInterfaceOrder.out(B.class);
       
    70   }
       
    71 
       
    72   interface L  {
       
    73     boolean v = TestInterfaceOrder.out(L.class);
       
    74     default void l() {}
       
    75   }
       
    76 
       
    77   static class C extends B implements L {
       
    78     static boolean v = TestInterfaceOrder.out(C.class);
       
    79   }
       
    80 
       
    81 
       
    82    static boolean out(Class c) {
       
    83        System.out.println("#: initializing " + c.getName());
       
    84        cInitOrder.add(c);
       
    85        return true;
       
    86    }
       
    87 
       
    88 }