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?
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" ).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With