2
int API_VERSION = 21;

@TargetApi(API_VERSION) is used in Android to specify that the method/class is supported for API_VERSION and below.

Can we mirror something similar which specifies that a method or class is supported for API_VERSION and above only?

Note:- I did not find any such annotation, but would like to ask the community if they have come across something like this or have implemented their own annotation?

ARK
  • 3,734
  • 3
  • 26
  • 29
  • What do you expect the effect of this annotation to be? The point behind annotations is to have compile-time or runtime effects. – CommonsWare Sep 27 '16 at 18:46
  • @CommonsWare I want the particular class/method to be called only on higher API Levels. This class/method uses Higher API Levels, say 21 and above. For eg, using material design for 21+, but not calling this on lower levels. nhaarman has a good answer. – ARK Sep 27 '16 at 18:54

1 Answers1

3

There is @RequiresApi:

Denotes that the annotated element should only be called on the given API level or higher.

This is similar in purpose to the older @TargetApi annotation, but more clearly expresses that this is a requirement on the caller, rather than being used to "suppress" warnings within the method that exceed the minSdkVersion.

Community
  • 1
  • 1
nhaarman
  • 98,571
  • 55
  • 246
  • 278