11

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)

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • This can fairly easily be averted by extracting the line(s) in question into a function and adding the annotation there, but the documentation specifically suggests that the annotation works in-line. – Paul Lammertsma Mar 23 '12 at 00:12

1 Answers1

5

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.

Tor Norbye
  • 9,062
  • 3
  • 29
  • 24