Deprecate in Java 1.6

10,648

Solution 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).

Solution 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.

Solution 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.

Solution 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.

Solution 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.

Share:
10,648
Ian Bishop
Author by

Ian Bishop

Architect distributed systems that live on AWS, written in Clojure at Serenova. You can contact me at bishop14 (at) gmail dot com. Me, elsewhere: Hacker News LinkedIn

Updated on June 05, 2022

Comments

  • Ian Bishop
    Ian Bishop about 2 years

    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?