Android 已弃用 kotlin 抑制警告 [英] kotlin suppress warning deprecated for Android

查看:43
本文介绍了Android 已弃用 kotlin 抑制警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Kotlin Android 项目中,我使用了一个从 api 23 开始被弃用的函数,它是最近的.所以我需要一种方法来禁用那些已弃用的警告.有没有简单的方法来做到这一点?

In my Kotlin Android project, I am using a function that has been deprecated starting from api 23, which is quite recent. So I need a way to disable those deprecated warnings. Is there an easy way to do so?

推荐答案

使用 @Suppress 带有参数的注解 "DEPRECATION":

@Suppress("DEPRECATION")
someObject.theDeprecatedFunction()

除了单个语句之外,您还可以使用注释标记函数、类或文件(@file:Suppress("DEPRECATION") 开头)以抑制所有弃用那里发出警告.

Instead of a single statement, you can also mark a function, a class or a file (@file:Suppress("DEPRECATION") in its beginning) with the annotation to suppress all the deprecation warnings issued there.

在 IntelliJ IDEA 中,这也可以通过 Alt+Enter 菜单完成,在带有弃用警告的代码上放置插入符号.

In IntelliJ IDEA this can also be done through Alt+Enter menu with caret placed on code with deprecation warning.

这篇关于Android 已弃用 kotlin 抑制警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆