Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class file not compatible with older versions of Java #38

Closed
SlimerDude opened this issue Apr 23, 2015 · 4 comments
Closed

Class file not compatible with older versions of Java #38

SlimerDude opened this issue Apr 23, 2015 · 4 comments
Labels

Comments

@SlimerDude
Copy link

Assuming the lib doesn't use any newer Java features, could the source be recompiled so it's compatible with older versions of Java?

Being a JDK 1.6 user I currently get:

Unsupported major.minor version 51.0

This SO question explains a bit more if you're unsure.

I know I can do it myself, but it's always nice not having to build from source.

@jdereg
Copy link
Owner

jdereg commented Apr 25, 2015

I believe there are uses of the 'diamond operator' used that may stop the
source from being compiled:

List<String> names = new ArrayList<>()

I have no problem with you forking the json-io repo, and modifying the
source there to be JDK 1.6 compliant. Then feel free to share the link to
your repo as the 1.6 json-io. I'd hope that you would keep it up-to-date
with changes to the Cedar Software json-io. I don't plan to move to JDK
1.8 until 1.7 is sunsetted. Even then, I will try to hold off. Lambda
functions would be the main enticement to move to JDK 1.8.

On Thu, Apr 23, 2015 at 1:53 PM, SlimerDude notifications@github.com
wrote:

Assuming the lib doesn't use any newer Java features, could the source be
recompiled so it's compatible with older versions of Java?

Being a JDK 1.6 user I currently get:

Unsupported major.minor version 51.0

This SO question
http://stackoverflow.com/questions/10382929/how-to-fix-unsupported-major-minor-version-51-0-error
explains a bit more if you're unsure.

I know I can do it myself, but it's always nice not having to build from
source.


Reply to this email directly or view it on GitHub
#38.

@SlimerDude
Copy link
Author

Generics were introduced in Java 1.5, so diamond operators shouldn't be a problem.

To produce backwards compatible class files shouldn't take much more than setting the target option in the compiler. Here's a link on how to set it in the Maven .pom file.

@jdereg
Copy link
Owner

jdereg commented Apr 25, 2015

The diamond operator (on the RHS) support was not added (as I understand
it) until Java 1.7. Please try it and see if you can compile the example
line I sent.

On Sat, Apr 25, 2015 at 8:14 AM, SlimerDude notifications@github.com
wrote:

Generics were introduced in Java 1.5, so diamond operators shouldn't be
a problem.

To produce backwards compatible class files shouldn't take much more than
setting the target option in the compiler. Here's a link on how to set it
in the Maven .pom file
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
.


Reply to this email directly or view it on GitHub
#38 (comment).

@SlimerDude
Copy link
Author

With regards to the line:

List<String> names = new ArrayList<>()

while the syntax is Java 1.7, the JDK can still compile it to Java 1.5 / 1.6 compatible byte code resulting in a class file usable by all (the purpose of the said target compiler option).

But on further inspection of the source code, I see you're using java.lang.ReflectiveOperationException in MetaUtils which was only introduced in Java 1.7 - so obviously those references won't resolve in earlier JDKs.

Oh well - I was only after a quick one-liner for pretty printing JSON. Hope you don't mind but I've gone with the usual GSON...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants