为何选择javac" -source"国旗不起作用? [英] Why javac "-source" flag doesn't work?

查看:101
本文介绍了为何选择javac" -source"国旗不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试 javac -source 标志,我对它应该如何工作有点困惑。

I am testing the javac -source flag and I am a bit confuse about how it is supposed to work.

请参阅此代码作为示例。它是一个不兼容的Java5代码,因为在该版本的JDK中没有为String定义 isEmpty()

See this code as an example. It is a non-compatible Java5 code as the method isEmpty() is not defined for String in that version of the JDK.

public class TestJavac {
   public static void Main(String args[]) {
   String pippo = "pippo";   
   pippo.isEmpty();
   }
}

尝试使用以下方式进行编译:

Trying to compile using:

javac -source 5 TestJavac.java

然后它有效!
这对我来说听起来很奇怪,但也许有些东西我无视。
我的 JAVA_HOME 指向 1.6 JDK

推荐答案

源选项仅适用于语言级别,不适用于API(由JDK运行时库提供)。

The source option is only for the language level, not for the API (supplied by the JDK runtime libraries).

有一个单独的选项(-bootclasspath -extdirs)来指定要使用的JDK(并且需要获取相应的jar文件)。

There is a separate option (-bootclasspath -extdirs) to specify which JDK to use (and you need to get the appropriate jar files).

请注意,还有-target(控制输出字节码版本)。

Note that there is also -target (which controls the output bytecode version).

你应该总是指定所有(或者甚至使用较旧的JDK编译,你或多或少需要在那一秒切换到工作)

You should always specify all (or even compile using the older JDK, which you more or less need anyway for that second switch to work)

这篇关于为何选择javac" -source"国旗不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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