Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kotlin suppress warning deprecated for Android

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?

like image 502
loloof64 Avatar asked Apr 17 '16 12:04

loloof64


People also ask

How do I turn off deprecation warning android?

The @SuppressWarnings annotation disables certain compiler warnings. In this case, the warning about deprecated code ( "deprecation" ) and unused local variables or unused private methods ( "unused" ).

What is deprecation warning?

Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.


1 Answers

Use @Suppress annotation with argument "DEPRECATION":

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

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.

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

like image 146
hotkey Avatar answered Sep 22 '22 09:09

hotkey