注释仅在源级别为5.0语法错误java时可用 [英] Annotations are only available if source level is 5.0 syntax error java

查看:194
本文介绍了注释仅在源级别为5.0语法错误java时可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编译一个普通的java程序与 @Override 注释(我从互联网下载一个来源从一些教程)。现在 javac 表示

I am compiling a normal java program with @Override annotation(I downloaded a source from internet from some tutorial). Now the javac is complaing that

注释仅在源级别为5.0

SO或其他网站上的每个问题都与eclipse有关,但我不使用eclipse。我从命令行编译代码。如何解决这个问题。

Every question on SO or other site relates this to eclipse but I am not using eclipse. I am compiling the code from command line. How can I resolve the problem.

以下是一些可能有用的信息:

Here is some information that may be useful:

$java -version
 java version "1.6.0_13-b03
 (some other not so useful info)

编辑:

$javac -version
 Eclipse Java Compiler v_677_R32x, 3.2.1 release,....

编译命令:

javac User.java

.java 只是普通的java文件。没有错误,除了这一个。

User.java is just normal java file. No errors there for sure except this one.

推荐答案

项目属性 - > Java Build Path / Libraries选项卡确保您具有JRE System Library 6 ennvironment。

In project properties->Java Build Path/Libraries tab make sure you have JRE System Library 6 ennvironment.

由于您不是通过eclipse构建,您必须使用-source参数给编译器告诉它使用更高的语言级别。有趣的是,似乎eclipse编译器中的默认值不是6,oracle编译器使用。

Since you aren't building through eclipse, you will have to use the -source parameter to the compiler to tell it to use a higher language level. Interestingly it seems the default in the eclipse compiler is not 6 which the oracle compiler uses.

这篇关于注释仅在源级别为5.0语法错误java时可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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