N
N
nuclear_kote2017-08-08 16:51:51
Java
nuclear_kote, 2017-08-08 16:51:51

How to determine which default method to call?

I have an interesting question about toad8 here: There are 2 interfaces with 2 default methods with the same name, how is it possible to determine which interface to pull the method from?

interface Test1 {
   default String test() {
      return "a";
   }
}

interface Test2 {
   default String test() {
      return "b";
   }
}

public class Abc implements Test1, Test2 {

   public static void main() {
       System.out.println(new Abc().test());
   }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Ray, 2017-08-08
@firezhek

This is not possible, the compiler will give an error due to a method collision)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question