views:

651

answers:

6

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?

A: 

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

Grzegorz Oledzki
+2  A: 

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.

Bozho
Sorry, fixed the spelling mistake. Will get back to you on the other stuff.
iano
A: 

@Deprecated not @Deprecate

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

MarkPowell
+1  A: 

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.

Jon Skeet
+6  A: 

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

gustafc
A: 

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.

BalusC