blob: b407698ce4fb629fcf8f6c8d9c5ec289cf407524 [file] [log] [blame]
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001// 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 Hertzca758652017-06-16 18:18:04 +02005public class DebugInterfaceMethod {
Sebastien Hertz964c5c22017-05-23 15:22:23 +02006
7 interface I {
8 default void doSomething(String msg) {
9 String name = getClass().getName();
10 System.out.println(name + ": " + msg);
11 }
Sebastien Hertzca758652017-06-16 18:18:04 +020012
13 static void printString(String msg) {
14 System.out.println(msg);
15 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020016 }
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 Hertzca758652017-06-16 18:18:04 +020034 private static void testStaticMethod() {
35 I.printString("I'm a static method in interface");
36 }
37
Sebastien Hertz964c5c22017-05-23 15:22:23 +020038 public static void main(String[] args) {
39 testDefaultMethod(new DefaultImpl());
40 testDefaultMethod(new OverrideImpl());
Sebastien Hertzca758652017-06-16 18:18:04 +020041 testStaticMethod();
Sebastien Hertz964c5c22017-05-23 15:22:23 +020042 }
43
44}