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