Why javac “-source” flag doesn't work?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 22:22:48

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

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

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

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)

Augusto

The source flag is used only to verify language features, from the documentation of -source flag:

1.3  The compiler does not support assertions, generics, or other
     language features introduced after Java SE 1.3.

1.4  The compiler accepts code containing assertions, which were 
     introduced in Java SE 1.4.

1.5  The compiler accepts code containing generics and other language 
     features introduced in Java SE 5.

5    Synonym for 1.5.

1.6  No language changes were introduced in Java SE 6. However, encoding 
     errors in source files are now reported as errors instead of warnings 
     as in previous releases of Java SE.

6    Synonym for 1.6.

1.7  This is the default value. The compiler accepts code with features 
     introduced in Java SE 7.

as you can see, no changes were introduced in java 6.

The -source only checks the java syntax, not the libraries included. e.g. it ignores the @since 1.6 :(

Similarly -target will produce classes which will load on an older version of the JVM but might not run.

http://vanillajava.blogspot.co.uk/2012/02/using-java-7-to-target-much-older-jvms.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!