问题

In Java 1.5, to deprecate a method you would:

@Deprecated int foo(int bar) {

}

Compiling this in Java 1.6 results in the following:

Syntax error, annotations are only

available if source level is 1.5

Any ideas?

回答1:

You have to tell the compiler to use 1.6:

javac -source 1.6

Or equivalent for your IDE/build system (as others have suggested).

回答2:

First, its @Deprecated, and second - double-check if you are really compiling with Java 1.6. What are you using? javac? Eclipse?

If using javac, make sure your JAVA_HOME is set to point to JDK 6, not JDK 1.4.2

If using Eclipse (or any IDE), right click the project > properties > and search for compiler level.

回答3:

Syntax error, annotations are only available if source level is 1.5

This is a typical IDE error message. You've configured the workspace or the project to use compliance level 1.4 or older. Assuming that it's Eclipse (it's at least recognizeable as an Eclipse error), then you need to go to Java > Compiler in workspace preferences and set the Compiler compliance level to 1.5 or newer. You need to check this in the Java Compiler entry in Project's properties as well.

回答4:

If you are using Eclipse IDE then

1- Select your project in Project Explorer

2- Go to Project -> Properties -> Java Compiler

3- Check the option for 'Enable project specific settings'

4- Set the 'Compiler compliance level' to '1.6'

NOTE: If already set to 1.6 then change it to 1.5.

5- Press the 'Apply' button.

There are issues with the IDE and at times it just doesn't pick up the default selected compiler compliance level. Therefore you have to toggle it and press the apply button for the changes to take effect.

回答5:

Having read the responses to date, I can see that there is some confusion as to what is happening where Eclipse is involved.

I had the same syntax error, checked workspace Java compliance (Window > Preferences > Java > Compiler) and was surprised to see a complier compliance level of 1.6. However, I noticed the link Configure Project Specific Settings at the top of this preference page. The link takes you to the project's own settings.

You can navigate there from the main menu, too. In this case Project > Properties > Java Compiler. There is a check box labelled Enable Project Settings and in my case this was checked and the setting was 1.4, though I do not remember setting it explicitly. Anyway, you can either let the compliance setting to default to that of the workbench or change the project setting to 1.5 or higher.

This should fix the syntax error.

回答6:

I suspect you've got your source level set to lower than 1.5. It should be fine in Java 6 in general.

How are you compiling? If it's with Eclipse, what do your project/workspace settings say under Compiler / JDK Compliance Level?

If you're using javac, run

javac -version

to check what version you're really using.

回答7:

Are you sure you are compiling with Java 1.6 not 1.4 (or older)?

What compiler are you using?

回答8:

@Deprecated not @Deprecate

If you are using Eclipse, make sure the settings for the Java Compiler are set to 1.6 compliance.

回答9:

This can occur even if java 1.6 is used in eclipse. Click the project and then right click it. Go to properties and in Java compiler section first check enable project specific then manually select 1.6 version even if it is already there by default. This fixed my problem.

来源:https://stackoverflow.com/questions/1790957/deprecate-in-java-1-6

jAvA中deprecate,Deprecate in Java 1.6相关推荐

  1. Java 中的 XML:Java 文档模型的用法

    Java 中的 XML:Java 文档模型的用法 英文原文 内容: 代码对比 DOM JDOM dom4j Electric XML XPP 结束语 下一次... 参考资料 关于作者 对本文的评价 相 ...

  2. 在java中使用JMH(Java Microbenchmark Harness)做性能测试

    文章目录 使用JMH做性能测试 BenchmarkMode Fork和Warmup State和Scope 在java中使用JMH(Java Microbenchmark Harness)做性能测试 ...

  3. java 泛型详解、Java中的泛型方法、 java泛型详解

    本文参考java 泛型详解.Java中的泛型方法. java泛型详解 概述 泛型在java中有很重要的地位,在面向对象编程及各种设计模式中有非常广泛的应用. 什么是泛型?为什么要使用泛型? 泛型,即& ...

  4. java中函数的调用,java中如何调用函数

    java动态调用函数,Java 中使用动态代码,java函数调用,java中如何调用函数 如何在 Java 中调用 C 函数 宗薇 [期刊名称]<网络新媒体技术> [年(卷),期]2000 ...

  5. Java中使用json时java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决

    Java中使用json时java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决 参考文章: (1)Java中使用json时java.lan ...

  6. java中hashcode_浅谈Java中的Hash值

    1.Hash值有什么用? HashMap.HashTable.HashSet,所以涉及到使用Hash值进行优化存储的地方,都会用到HashCode.HashCode是Key,这种计算为提高计算的性能. ...

  7. java中的action_浅析java中action的作用

    正如早先指出的那样,action()并不是我们对所有事进行分类后自动为handleEvent()调用的唯一方法.有三个其它的被调用的方法集,如果我们想捕捉某些类型的事件(键盘.鼠标和焦点事件),因此我 ...

  8. 在java中表示json_在Java中解析JSON而不知道JSON格式

    我试图解析在Java中的JSON字符串,并找到键值对,使我可以确定JSON对象的近似结构,因为JSON字符串的对象结构是未知的. 例如,一个执行可能有一个JSON字符串,如下所示: {"id ...

  9. JAVA中throw用法例子,Java Optional orElseThrow()用法及代码示例

    Java中的java.util.Optional类的orElseThrow()方法用于获取此Optional实例(如果存在)的值.如果此Optional实例中不存在任何值,则此方法将引发从指定供应商生 ...

  10. java中如何就绝对定位,Java中如何定位资源

    Java中如何定位资源 本文来自:http://blog.csdn.net/ruyanhai/archive/2007/11/07/1871663.aspx ◆ 一般情况下,我们都使用相对路径来获取资 ...

最新文章

  1. 【ACM】LightOJ - 1010 Knights in Chessboard(不是搜索...)
  2. 深入理解:RabbitMQ的前世今生
  3. 在中国,程序员这行能干一辈子吗?
  4. SAP Fiori应用Footerbar区域按钮的高亮显示逻辑
  5. 【Linux】/dev/null 21 详解
  6. 搞笑日常:有位程序员的老爸是个什么感觉?过程你绝对意想不到!
  7. combox数据过滤 wpf_- - WPF:筛选ItemCollection的ComboBox也会筛选绑定到同一ComboBoxes的其他ItemsSource_c#_酷徒编程知识库...
  8. 【静默】Oracle各类响应文件何在?
  9. 堆排序实现(C++)
  10. java severlet 例子_Java开发Servlet实例
  11. Java速成:37-贷款计算器
  12. vivado 开发教程(三) 在SDK中创建应用工程
  13. 淘宝登录破解(滑动验证码破解,淘宝登录环境检测破解)
  14. Linux系统管理---linux计划任务和日志的管理
  15. 微信小程序连接蓝牙打印机打印快递面单
  16. Activity的生命周期和启动模式
  17. 智能文档控制——文档的智能归档、捕获、索引、访问和协作
  18. Centos更新内核
  19. 个性化学习推荐系统的设计与实现
  20. 编写可读代码,提高工作效率

热门文章

  1. SpringCloud Sleuth入门介绍
  2. 解决layui form组件使用botton按钮提交页面自动刷新问题
  3. 兼容微信字体变大,页面错乱问题
  4. 什么是精神内耗,如何防止?
  5. Python爬取煎蛋网多页的图片
  6. 班级主页效果图html,DW制作网页|html静态页面|班级网页素材|蝶恋花班级主页网站...
  7. x86 单线并发多拨_OpenWrt ADSL单线多拨,负载均衡(仅供参考)
  8. win10虚拟机环境下运行驱动程序
  9. 如何检测猥琐的私有SDWAN隧道协议
  10. leetcode 812. Largest Triangle Area(python)