Kotlin suppression warning is deprecated for Android

In my Kotlin project for Android, I use a function that has been deprecated since API 23, which is quite recent. So I need a way to disable these deprecated warnings. Is there an easy way to do this?

+11
source share
2 answers

Use the @Suppress annotation with the argument "DEPRECATION" :

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

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

In IntelliJ IDEA, this can also be done using the Alt + Enter menu with a carriage placed in the failure warning code.

+33
source

In Kotlin

@SuppressWarnings

changes to

@Suppress

To remove a strike with obsolete warnings, you must add

  @Suppress("DEPRECATION") 

to remove the warning from the super method. By adding

 @Suppress("OverridingDeprecatedMember") 

Function warning will be deleted. So, the full annotation will be:

 @Suppress("OverridingDeprecatedMember", "DEPRECATION") 

As an additional note, erasing should be written as "DEPRECATION" (use uppercase letters)

+3
source

Source: https://habr.com/ru/post/1265287/


All Articles