0

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>
halfer
  • 19,824
  • 17
  • 99
  • 186
Plutoverse
  • 13
  • 4
  • Your question is missing the most important information -- the abstract methods in the RuleListener interface. Please post that information with your question. – Hovercraft Full Of Eels Nov 15 '21 at 23:28
  • Also, it is suspicious to me that your `onFailure` method does not have an `@Override` annotation above it, suggesting that your method signature is likely wrong. – Hovercraft Full Of Eels Nov 15 '21 at 23:28
  • Here is the class I am implementing https://github.com/j-easy/easy-rules/blob/master/easy-rules-core/src/main/java/org/jeasy/rules/api/RuleListener.java – Plutoverse Nov 15 '21 at 23:31
  • Please add the entire error message(s) that you see. – Hovercraft Full Of Eels Nov 15 '21 at 23:35
  • Here you go...The method onSuccess(Rule, Facts) of type PositionalStrengthListener must override or implement a supertype method PositionalStrengthListener.java /Everest/src/main/java/rules line 17 Java Problem – Plutoverse Nov 15 '21 at 23:37
  • Did you add easy-rules as a [project dependency in your pom.xml](https://mvnrepository.com/artifact/org.jeasy/easy-rules/3.2.0)? That XML is needed so the project knows where to find depended-upon code. – Rogue Nov 15 '21 at 23:50
  • Please see the pom.xml snippets I appended to my question. – Plutoverse Nov 15 '21 at 23:53
  • Please note that easy rules implementation is working in general. I am running into issue implementing my first RuleListener due to this @Override error message. – Plutoverse Nov 15 '21 at 23:54
  • 2
    Check your `import` statements for `Rule` and `Facts` - are they importing the correct class? – greg-449 Nov 16 '21 at 08:10
  • Yes @greg-449. I have the import statements: import org.jeasy.rules.api.Facts; import org.jeasy.rules.api.RuleListener; – Plutoverse Nov 16 '21 at 17:09
  • Do you import `Rule`? You only mentioned 2 import statements. – Johannes Kuhn Nov 23 '22 at 20:19

1 Answers1

0

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.