kotlin suppress warning deprecated for Android

后端 未结 2 1756
温柔的废话
温柔的废话 2020-12-15 16:11

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 warning

2条回答
  •  天涯浪人
    2020-12-15 16:24

    In Kotlin

    @SuppressWarnings

    is changed to

    @Suppress

    For removing the strike through deprecation warnings you should add,

     @Suppress("DEPRECATION")
    

    to remove the warning from the super method. By adding

    @Suppress("OverridingDeprecatedMember")
    

    The warning of the function will get removed. So, the complete annotation will be;

    @Suppress("OverridingDeprecatedMember", "DEPRECATION")
    

    As an additional note the deprecation should be written as "DEPRECATION" ( use capital letters)

提交回复
热议问题