Kotlin禁止Android弃用警告 [英] kotlin suppress warning deprecated for Android

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

问题描述

在我的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.

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

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