微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

RequiresApi和TargetApi的android注释

RequiresApi和TargetApi有什么区别?

kotlin的样品:

@RequiresApi(api = Build.VERSION_CODES.M)
@TargetApi(Build.VERSION_CODES.M)
class FingerprintHandlerM() : FingerprintManager.AuthenticationCallback()

注意:FingerprintManager.AuthenticationCallback需要api M

注2:如果我不使用TargetApi lint失败与错误类需要api级别23 …

解决方法

类似于Mike所说,正如您在文档中可以看到的那样:

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.

正如你可以看到的,这实际上是强制调用者来验证调用方法时使用的API,而不是从IDE / LINT中删除警告.

您可以将其与@NonNull或@Null注释进行比较,他们强制调用者可以/不能向函数发送空值.

原文地址:https://www.jb51.cc/android/310122.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐