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

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

问题描述

我正在编译一个带有 @Override 注释的普通 Java 程序(我从互联网上的某个教程下载了一个源代码).现在 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 或其他网站上的每个问题都与日食有关,但我没有使用日食.我正在从命令行编译代码.我该如何解决这个问题.

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

User.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 环境.

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

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

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天全站免登陆