Method does not override or implement a method from a supertype on Eclipse with interface and Easy Rules

1k Views Asked by At

Compiler compliance configuration in Eclipse

I am running into this popular error "method does not override or implement a method from a supertype" in my code. I have spent nearly 5 hours reading on various solutions offered in the past and none of them are helping me. What is it that I am missing?

Here are the things that I have tried:

  1. Made sure that the compiler compilation is set to 1.8
  2. JRE is 1.8
  3. Exited and re-imported my eclipse project in java to see if that helps
  4. mvn clean install -U
  5. Used to below properties in my pom.xml file
<properties>
      <maven.compiler.target>1.8</maven.compiler.target>
      <maven.compiler.source>1.8</maven.compiler.source>
    </properties>
  1. Used another way of mentioning java versions for target and source as below
<plugins>
  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>    
        </configuration>
        <version>3.8.1</version>
      </plugin>
     </plugins>

What am I doing?

I am using Easy Rules. I implemented RuleListener as below: I keep getting the "method does not override or implement a method from a supertype".

public class PositionalStrengthListener implements RuleListener {
    private static Logger logger = LoggerFactory.getLogger(PositionalStrengthListener.class);

    @Override
    public void onSuccess(Rule rule, Facts facts) {
        logger.debug("OnSuccess: PositionalStrengthListener");
  
    }

    public void onFailure(Rule rule, Facts facts, Exception exception) {
        logger.debug("On failure:PositionalStrengthListener");
    }

}

I am implementing this interface: https://github.com/j-easy/easy-rules/blob/master/easy-rules-core/src/main/java/org/jeasy/rules/api/RuleListener.java

I was focusing on OnSuccess @Override error message and hence didn't add @Override on OnFailure but I get the same error with OnFailure if I add @Override.

Below is the easy rules dependency in pom.xml file.

<!-- https://mvnrepository.com/artifact/org.jeasy/easy-rules -->
    <dependency>
         <groupId>org.jeasy</groupId>
        <artifactId>easy-rules-core</artifactId>
         <version>4.1.0</version>
    </dependency>
    <dependency>
         <groupId>org.jeasy</groupId>
        <artifactId>easy-rules-support</artifactId>
         <version>3.3.0</version>
    </dependency>
1

There are 1 best solutions below

0
Smooth Carlito On

You responded to greg-449's comment about the imports, but didn't mention what import you are using for Rule. Since jeasy has two Rule classes, I think it would be worth double checking this.

It should be org.jeasy.rules.api.Rule. I'm able to reproduce the compile error by changing the import to org.jeasy.rules.annotation.Rule instead.

As a side-note, consider using version 4.1.0 of easy-rules-support instead of 3.3.0. It's not causing this problem, I just think it's a good idea to keep them in sync unless there's a specific reason you can't.