RequiresApi vs TargetApi android annotations

前端 未结 5 1432
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 09:48

Whats the difference between RequiresApi and TargetApi?

Sample in kotlin:

@RequiresApi(api = Build.VERSION_CODES.M)
@Target         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 10:19

    From the JavaDocs in https://developer.android.com/reference/android/support/annotation/RequiresApi.html:

    [@RequiresApi] 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.

    I suppose they're functionally equivalent but @RequiresApi seems to be newer and has a higher chance of being extended to include more functionality.

提交回复
热议问题