4

I have Base interface:

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

I have extending 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 is not compiled, as: 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?

7
  • 4
    I assume your method is not called do as this is a reserved keyword in Java. Commented Nov 11, 2017 at 11:29
  • 2
    once you change the name do to something else you'll be fine. Commented Nov 11, 2017 at 11:30
  • Compiles fine in Java 8. Just need to use something else than do for the method name. Commented Nov 11, 2017 at 11:31
  • 3
    1.8.0_144, but I doubt that it matters. If you're actually using that compiler, then you're probably compiling with a -source or -target flag set to 1.7 or lower. Commented Nov 11, 2017 at 11:41
  • 2
    @RobbyCornelissen, this was the issue - one of the modules had 1.6 source for some reason. Now it is OK. If you make it into separate answer, I will mark it as correct. Thank you Commented Nov 11, 2017 at 11:48

2 Answers 2

2

If you're using a Java 8 compiler, the only way that your code can cause that compilation error is if the value of the -source flag that is passed to the compiler is set to 1.7 or lower.

Something like:

javac -source 1.7 ...

If you're using maven, the property setting below will have the same effect.

<maven.compiler.source>1.7</maven.compiler.source>
Sign up to request clarification or add additional context in comments.

Comments

0

You can't call method do because it's java reserved word. All list of Java keywords you can find here.

3 Comments

@Aominè changed. I mean give it name. Changed.
This was just for example, bad for this
It means that Java's reserved keywords can't be used for naming methods or variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.