在Java 6中编译,在7中运行 - 如何指定useLegacyMergeSort? [英] Compile in Java 6, run in 7 - how to specify useLegacyMergeSort?
问题描述
我想知道我是否在Java 6中编译,但有人在Java 7上运行该程序,是否会使用Java 6或7版本的Arrays.sort?
I'm wondering if I compile in Java 6, but someone runs the program on Java 7, will the Java 6 or 7 version of Arrays.sort be used?
这很重要,因为新的mergesort会抛出IllegalArgumentException,旧的则不会抛出(参见比较方法违反了它的一般合同!仅限Java 7 )
It's important because the new mergesort throws an IllegalArgumentException, and the old one doesn't (see Comparison method violates its general contract! Java 7 only)
现在,可以使用Arrays.useLegacyMergeSort在Java 7中编译,但很明显,该标志不适用于Java 6 - 我们希望在Mac OS Snow Leopard(使用6)上兼容。
Now, it's possible to compile in Java 7 using Arrays.useLegacyMergeSort, but obviously that flag isn't available for Java 6 - and we want to be compatible on Mac OS Snow Leopard (which uses 6).
出于某种原因(请参阅 http://madbean.com/2006/target14/ )-target编译器标志没有似乎产生兼容的代码,所以我们宁愿用Java 6编译。
For some reason (see http://madbean.com/2006/target14/) the -target compiler flag doesn't seem to produce compatible code, so we'd rather compile in Java 6.
有什么建议吗?
推荐答案
尝试设置系统属性
java -Djava.util.Arrays.useLegacyMergeSort = true ...
请注意,它不是来自Arrays公共API,而是来自src
Note that it's not from Arrays public API but from src
/**
* Old merge sort implementation can be selected (for
* compatibility with broken comparators) using a system property.
* Cannot be a static boolean in the enclosing class due to
* circular dependencies. To be removed in a future release.
*/
static final class LegacyMergeSort {
private static final boolean userRequested =
java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"java.util.Arrays.useLegacyMergeSort")).booleanValue();
}
这篇关于在Java 6中编译,在7中运行 - 如何指定useLegacyMergeSort?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!