Stephan Herhut | d5aa092 | 2017-05-22 16:06:14 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package classmerging; |
| 5 | |
| 6 | public class Test { |
| 7 | |
| 8 | public static void main(String... args) { |
| 9 | GenericInterface iface = new GenericInterfaceImpl(); |
| 10 | callMethodOnIface(iface); |
| 11 | GenericAbstractClass clazz = new GenericAbstractClassImpl(); |
| 12 | callMethodOnAbstractClass(clazz); |
| 13 | ConflictingInterfaceImpl impl = new ConflictingInterfaceImpl(); |
| 14 | callMethodOnIface(impl); |
| 15 | System.out.println(new SubClassThatReferencesSuperMethod().referencedMethod()); |
Christoffer Quist Adamsen | bfdbe60 | 2019-10-18 12:03:31 +0200 | [diff] [blame] | 16 | Outer outer = new Outer(); |
| 17 | Outer.SubClass inner = outer.getInstance(); |
| 18 | System.out.println(outer.getInstance().method()); |
Stephan Herhut | d5aa092 | 2017-05-22 16:06:14 +0200 | [diff] [blame] | 19 | System.out.println(new SubClass(42)); |
Christoffer Quist Adamsen | bfdbe60 | 2019-10-18 12:03:31 +0200 | [diff] [blame] | 20 | |
| 21 | // Ensure that the instantiations are not dead code eliminated. |
| 22 | escape(clazz); |
| 23 | escape(iface); |
| 24 | escape(impl); |
| 25 | escape(inner); |
| 26 | escape(outer); |
Stephan Herhut | d5aa092 | 2017-05-22 16:06:14 +0200 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | private static void callMethodOnIface(GenericInterface iface) { |
| 30 | System.out.println(iface.method()); |
| 31 | } |
| 32 | |
| 33 | private static void callMethodOnAbstractClass(GenericAbstractClass clazz) { |
| 34 | System.out.println(clazz.method()); |
| 35 | System.out.println(clazz.otherMethod()); |
| 36 | } |
| 37 | |
| 38 | private static void callMethodOnIface(ConflictingInterface iface) { |
| 39 | System.out.println(iface.method()); |
| 40 | System.out.println(ClassWithConflictingMethod.conflict(null)); |
| 41 | System.out.println(OtherClassWithConflictingMethod.conflict(null)); |
| 42 | } |
Christoffer Quist Adamsen | bfdbe60 | 2019-10-18 12:03:31 +0200 | [diff] [blame] | 43 | |
| 44 | @NeverInline |
| 45 | static void escape(Object o) { |
| 46 | if (System.currentTimeMillis() < 0) { |
| 47 | System.out.println(o); |
| 48 | } |
| 49 | } |
Stephan Herhut | d5aa092 | 2017-05-22 16:06:14 +0200 | [diff] [blame] | 50 | } |