Java requires a default method

I have a Base interface:

public interface Doable {
    void doAction(String str);
}

I have an interface:

public interface DoubleDoable extends Doable{
  @Override 
  default void doAction(String str) {
      doOnce();
      doOnce();
  }

  void doOnce();
}

And I have an implementation:

public class Action implements DoubleDoable {
    public void doOnce() {
      System.out.println(123);
    }
}

However, it does not compile like: Error:(10, 8) java: Action is not abstract and does not override abstract method doAction(java.lang.String) in Doable

Am I doing something wrong?

+4
source share
2 answers

If you use the Java 8 compiler, the only way your code can cause a compilation error is that the value of the flag -sourcepassed to the compiler is equal to 1.7or lower.

Sort of:

javac -source 1.7 ...

If you use maven, the value of the property below will have the same effect.

<maven.compiler.source>1.7</maven.compiler.source>
+2
source

You cannot call a method dobecause it is a java reserved word. You can find the entire list of Java keywords here .

0

Source: https://habr.com/ru/post/1689113/


All Articles