https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

ankushg

11/16/2021, 7:52 AM
Doing a cleanup of a codebase and marking some stuff as
@Deprecated
A couple pain points that are popping up: 1. Deprecated code tends to call other deprecated code, and this generates too many warnings. I currently have a ton of
@Suppress("KotlinDeprecation", "DEPRECATION") @Deprecated
declarations all over my codebase, when there are only one or two actual places that are using the top-level, public Deprecated method. 2. Deprecations in
import
statements are tricky.
When I intentionally use a deprecated declaration, I can
@Suppress
it at the call site. But I can't
@Suppress
the warning I get just for importing it! For top-level declarations, I can use the fully-qualified name everywhere and just avoid importing the deprecated declaration. This doesn't work when you're using an extension function contained in an
object
though. Questions: • Is there a way to automatically suppress Deprecation warnings within declarations that are also Deprecated? • Is there a way to get the compiler to ignore when a
@Deprecated
declaration is imported, but still warn when it is used? • Or alternatively: is there a way I can use a fully-qualified name to avoid importing an extension function contained in an
object
?
r

Ruckus

11/16/2021, 3:28 PM
You could just suppress deprecation warnings for the entire file (assuming the code is organized in such a way that deprecated stuff is clumped together in files without non-deprecated stuff).
a

ankushg

11/16/2021, 3:38 PM
Yeah that's my current fallback but there are definitely files that have only one deprecated method that imports other deprecated stuff and many perfectly fine methods that I don't want to suppress deprecations for 😔