jts
jts

Reputation: 715

jdk7 compliance level: how to migrate code source from 6 to 7

I am looking for a way to have javac emit warnings for code source that can be migrated from level 6 to level 7 so that I can have the code to be in level 7 mode?

Upvotes: 2

Views: 1871

Answers (3)

jts
jts

Reputation: 715

solution

Basically you can configure Eclipse to emit warnings for specific JDK 7 features that can be used

Upvotes: 0

Mac
Mac

Reputation: 14791

I'm reading the question as "how can I detect code that can be migrated from Java 6 paradigms to Java 7 paradigms". Examples might be use of the diamond operator:

List<Foo> bar = new ArrayList<>(); // instead of new ArrayList<Foo>()

And multicatch:

try { }
catch (FooException | BarException e) { }
/*
Instead of:
catch (FooException e) { }
catch (BarException e) { }
*/

If that's the case, a source code style checker (such as PMD, etc) should be able to highlight these opportunities.

For example, the NetBeans EasyPMD plugin routinely flags these two particular cases (as well as others, I'm sure) and offers suggestions for conversion to JDK 7 equivalents. Where a pre-JDK-7 code structure is discovered it is highlighted with a warning icon, and clicking the icon gives a suggested refactor to the JDK-7 equivalent.

I guess it's not really part of the compilation process per se (although you could automate it as part of the build process using Ant, for example), but it's the next best thing.

Upvotes: 2

Alexis Dufrenoy
Alexis Dufrenoy

Reputation: 11946

This article should help you:

http://www.oracle.com/technetwork/java/javase/compatibility-417013.html

However, incompatibilities should be minor. Your first step should be to compile your source code with a Java 7 compiler.

Going through the article, I would say the main incompatibiliy on language level is the difference of behavior with inherited exceptions (second item in the list). The others are differences in the libraries.

Upvotes: 1

Related Questions