Christoffer Quist Adamsen | bde428a | 2018-06-11 09:23:10 +0200 | [diff] [blame] | 1 | // Copyright (c) 2018, 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 | |
| 5 | package classmerging; |
| 6 | |
| 7 | public class TemplateMethodTest { |
| 8 | |
| 9 | public static void main(String[] args) { |
| 10 | AbstractClass obj = new AbstractClassImpl(); |
| 11 | obj.foo(); |
Christoffer Quist Adamsen | bfdbe60 | 2019-10-18 12:03:31 +0200 | [diff] [blame] | 12 | |
| 13 | // Ensure that the instantiations are not dead code eliminated. |
| 14 | escape(obj); |
| 15 | } |
| 16 | |
| 17 | @NeverInline |
| 18 | static void escape(Object o) { |
| 19 | if (System.currentTimeMillis() < 0) { |
| 20 | System.out.println(o); |
| 21 | } |
Christoffer Quist Adamsen | bde428a | 2018-06-11 09:23:10 +0200 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | private abstract static class AbstractClass { |
| 25 | |
| 26 | public void foo() { |
| 27 | System.out.println("In foo on AbstractClass"); |
| 28 | bar(); |
| 29 | } |
| 30 | |
| 31 | protected abstract void bar(); |
| 32 | } |
| 33 | |
| 34 | public static final class AbstractClassImpl extends AbstractClass { |
| 35 | |
| 36 | @Override |
| 37 | public void bar() { |
| 38 | System.out.println("In bar on AbstractClassImpl"); |
| 39 | } |
| 40 | } |
| 41 | } |