JDK何时编译版本很重要? [英] When Does The JDK Compile Version Matter?

查看:92
本文介绍了JDK何时编译版本很重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建两个Java工件.一个需要在1.6中构建,因为PowerMock与1.7不兼容,并且我们在许多单元测试中都使用了它.现在无法重构PowerMock,因为这将花费太多时间.

I have two Java artifacts being built. One needs to be built in 1.6, because PowerMock isn't compatible w/ 1.7 and we are using it in a lot of unit tests. Refactoring PowerMock out right now isn't an option as it will take too much time.

但是,我想在1.7内置的Java应用程序中使用此工件,并在1.7中运行整个程序.我认为应该没问题,因为它只是在构建一些类文件,我怀疑这些文件是否有可能早在1.2或更早的时候发生了很大的变化.无论如何,我显然对此有一个模糊的理解,并且我有兴趣让Java专家深入解释一下什么时候重要,什么时候不重要以及为什么.

However, I want to use this artifact in a Java application built in 1.7 and run the whole thing in 1.7. I think that it should be Ok since it is just building some class files, which I doubt changed much if any probably as far back as 1.2 or earlier. Anyway, I obviously have a fuzzy understanding of this and I am interested to get a Java experts deep dive explanation as to when this would matter, when it wouldn't, and why.

谢谢!

推荐答案

Java通常在版本之间向后兼容,因此在旧版本上编译的任何内容都应在较新的JVM上正常运行.实际上,除非它们需要更新的功能以允许更多仍然停留在旧JVM上的用户使用,否则许多通用库都以尽可能旧的版本(通常现在是Java 5)进行编译.

Java is usually backwards compatible between versions so anything compiled on an old version should run fine on a newer JVM. In fact a lot of common libraries are compiled in as old a version as possible (usually Java 5 now a days) unless they need a newer feature to allow more people who are still stuck on old JVMs.

话虽如此,您需要担心一些陷阱.我在Java 6到7进行某种转换时遇到的一个问题是TreeMap,其初始值为null

Having said that, there are a few gotchas you need to worry about. One problem I had on some Java 6 to 7 conversion was TreeMap with an initial value of null http://hariharanselvarajan-java.blogspot.com/2013/02/treemap-in-java-6-and-java-7.html

编辑 这是Oracle的链接,讨论了6和7之间不兼容的内容,尽管我认为这只会影响重新编译的内容:

EDIT Here is a link to Oracle discussing what isn't compatible between 6 and 7 although I would imagine this only affects things that are recompiled: http://www.oracle.com/technetwork/java/javase/compatibility-417013.html

这篇关于JDK何时编译版本很重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆