0

I'm using JDK 1.8 version. And had imported some already written code. Got an error like below

The method actionPerformed(ActionEvent) of type new ActionListener(){} must override a superclass method

Googled, tured out that I need to setCompiler compliance level in Eclipse to 1.6 and problem solved.

Got 2 doubts

1) If I set 1.6, How my 1.8 jdk (Installed in my machine) is able to produce 1.6 versions of files and run it too ? Is it possible 1.8 can produce 1.6 versions of java files and run it too ?

2) Is higher level of compliance level can handle lower verions, becasue its derived from lower to higher ? If yes, then why its even required to change the compliance level, if it can be handled ?

Does my doubts makes sense ?

Maria
  • 452
  • 1
  • 6
  • 20
  • 1
    Don't believe everything you find on the net. It might describe a totally different problem. In any way make sure you are importing the correct `ActionEvent` class. There are two of them in Java 8: `java.awt.event.ActionEvent` and `javafx.event.ActionEvent`. I assume the first one is the one you need. If you import the second one then you may end up with such an error message. – Robert Mar 31 '20 at 16:04
  • 1
    If you're referring to the answers in question "[Why do I get “must override a superclass method” with @Override?](https://stackoverflow.com/q/8697513/5221149)", then they are referring to **upgrading** compliance level from 1.5 to 1.6 (**or later**). You should set compliance level to the same version as the java you're using, so it should be 1.8, not 1.6. – Andreas Mar 31 '20 at 16:06

1 Answers1

0

tured out that I need to set Compiler compliance level in Eclipse to 1.6

No, you don't need to do that, and most likely it is a very bad idea. Setting compiler compliance level to 1.6 instructs your modern Java compiler to pretend it is the old Java 6 compiler. This means old code doesn't have to be modified to work with the new language version, but it also means you will be unable to use any language features that have been added to the Java language in the last 15 years. That sounds like a very high price to pay to avoid having to slightly adjust old code to compile under a new Java version.

meriton
  • 68,356
  • 14
  • 108
  • 175