Allen H.
Allen H.

Reputation: 358

Eclipse Java - Set compiler to Java 6 but still have Java 7 methods/libraries and no complains

For a project I must use Java 6, so I set my eclipse compiler setting to 1.6 (JDK compliance level).

However, I included java.nio.file.Files which is a Java 7 library and I am not getting any complaints. I can ensure that my project specific setting is set to 1.6. I even changed my entire workspace to 1.6 and rebuilt, still no complaints. My colleagues are seeing the complaint on java.nio.files.

Is it becuase I have a jdk7 which is recognizing the java.nio.file.Files even when set to 1.6 spcs?

Upvotes: 3

Views: 3473

Answers (3)

M_I
M_I

Reputation: 132

Java 6 is able to interpret java.nio.file.Files because there is no special Java 7 syntax in contrast to Java 7 and Java 8 (lambda expressions etc.). So you are working on standard libraries. Uninstall Java 7 JDK and install Java 6 JDK and you will that java.nio.file.Files is not available anymore.

Upvotes: 1

GhostCat
GhostCat

Reputation: 140417

These are two different things:

  • the compliance level is about the syntax that you can use when writing Java code (respectively about the Java version number that gets put into compiled byte code)
  • but the libraries that are available to you depend on the JDK that your project is using!

In other words: if you truly want to restrict your project to Java 6 libraries, you will have to install a Java 6 JDK on your system, and point to that within your project setup ( most likely, your current project setup makes use of a newer-than-Java-6 JDK ).

And the usual disclaimer: Java 6 has had end of life many years ago. You should do whatever you can to upgrade your setup.

Upvotes: 2

Malt
Malt

Reputation: 30285

JDK compliance level is the level of the Java syntax, not the runtime libraries. It will just prevent you from using language features that were introduced in later versions like try-with-resources which was introduced in JDK 7.

If you want to develop for JDK6, you need to use JDK6.

Upvotes: 1

Related Questions