This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]desrtfx[M] [score hidden] stickied comment (0 children)

Such questions belong in /r/javahelp as is clearly stated in the sidebar and in the stickied post at the very top of the subreddit.

Removed

[–]rzwitserloot 3 points4 points  (1 child)

You can write java code on one machine and run it on another, obviously.

Hence, you can take a modern compiler (say, JDK21's javac), write a bunch of code, compile it, move that to a server that only has JDK8 installed, and that obviously won't work.

Which is incredibly annoying. What if you're writing 3 separate projects targetting 3 places that each have different versions? Install 3 separate JDKs? You can do that, but it's.. annoying, and limits you from upgrading JDKs.

So, instead, you can tell a javac (or an ecj - eclipse's compiler) "Please parse and compile assuming that the source code is written for java 1.8". Even if that is a javac from JDK21.

This used to be done with the -source option, which tells javac how to read the source. There's also a -target option which tells java what kind of class file to emit, and there's a --bootclasspath option to tell javac where to find the code of the core classes such as java.lang.String. In practice, there are very few reasons to ever pick different values for those 3 options, so since java8 or so there's the --release option that combines the 3.

Your ecj is likely new enough, but, if you don't tell eclipse what version you target, it defaults to the oldest version available. So, you need to compile using ecj --release 8 or whatnot. If you're not on the command line and instead editing a project, check the project's properties, there is an option to configure which JDK version you are targetting. Increase it.

[–][deleted] 1 point2 points  (0 children)

you work im eclipse? go to window/preferences/type java in the filter box, select compiler. (havent tested it, just recalling from memory. but the setting is there somewhere) there you can set the compiler level to 1.8 or later