Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +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 | |
Sebastien Hertz | ca75865 | 2017-06-16 18:18:04 +0200 | [diff] [blame] | 5 | public class DebugInterfaceMethod { |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 6 | |
| 7 | interface I { |
| 8 | default void doSomething(String msg) { |
| 9 | String name = getClass().getName(); |
| 10 | System.out.println(name + ": " + msg); |
| 11 | } |
Sebastien Hertz | ca75865 | 2017-06-16 18:18:04 +0200 | [diff] [blame] | 12 | |
| 13 | static void printString(String msg) { |
| 14 | System.out.println(msg); |
| 15 | } |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | static class DefaultImpl implements I { |
| 19 | } |
| 20 | |
| 21 | static class OverrideImpl implements I { |
| 22 | |
| 23 | @Override |
| 24 | public void doSomething(String msg) { |
| 25 | String newMsg = "OVERRIDE" + msg; |
| 26 | System.out.println(newMsg); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | private static void testDefaultMethod(I i) { |
| 31 | i.doSomething("Test"); |
| 32 | } |
| 33 | |
Sebastien Hertz | ca75865 | 2017-06-16 18:18:04 +0200 | [diff] [blame] | 34 | private static void testStaticMethod() { |
| 35 | I.printString("I'm a static method in interface"); |
| 36 | } |
| 37 | |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 38 | public static void main(String[] args) { |
| 39 | testDefaultMethod(new DefaultImpl()); |
| 40 | testDefaultMethod(new OverrideImpl()); |
Sebastien Hertz | ca75865 | 2017-06-16 18:18:04 +0200 | [diff] [blame] | 41 | testStaticMethod(); |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | } |