提供向后兼容性时,如何摆脱弃用警告? [英] How to get rid of deprecation warnings when providing backwards compatibility?

查看:194
本文介绍了提供向后兼容性时,如何摆脱弃用警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何消除棉绒折旧警告?例如,烦人的NetworkInfo:

How one can get rid of linter deprecation warnings? For example, the annoying NetworkInfo:

warning: [deprecation] NetworkInfo in android.net has been deprecated

推荐答案

为了消除此类过时警告,在提供向后兼容性时,
必须删除不能应用的import @SuppressWarnings("deprecation"):

In order to get rid of such deprecation warnings, when providing backwards compatibility,
one has to remove the import, to which one cannot apply @SuppressWarnings("deprecation"):

// import android.net.NetworkInfo;

,然后使用完全限定的类名android.net.NetworkInfo而不是NetworkInfo.关键是,只能将@SuppressWarnings("deprecation")应用于方法,而不能应用于导入.

And then use it's fully qualified class name android.net.NetworkInfo instead of NetworkInfo. The point is, that one can only apply @SuppressWarnings("deprecation") to methods, but not imports.

这篇关于提供向后兼容性时,如何摆脱弃用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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