Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-line annotations give syntax errors

I'm loving the new Lint API checks of ADT rev 17, but the new API Correctness Check has got me stumped. I have the following line of code:

listView.setOverScrollMode(OVER_SCROLL_NEVER);

Lint is reporting on this line:

Call requires API level 9 (current min is 4)

According to the documentation, I should just be able to add an annotation above the line, like so:

@TargetApi(9)
listView.setOverScrollMode(OVER_SCROLL_NEVER);

This, however, gives a syntax error in Java 1.6:

Syntax error on token(s), misplaced construct(s)

like image 889
Paul Lammertsma Avatar asked Mar 22 '12 12:03

Paul Lammertsma


1 Answers

That's not allowed in Java (until/if JSR 308 gets added); you can only annotate classes, methods, fields, parameters and variable declarations. It's the latter that is shown in the docs. However, for bytecode based checks like the api check you may need to place it on a method or class (or anonymous/inner class). The Add Annotation quickfix for these warnings in lint should do the right thing.

like image 67
Tor Norbye Avatar answered Nov 15 '22 15:11

Tor Norbye