What warning do you have to suppress to still use ...
# library-development
l
What warning do you have to suppress to still use a deprecated symbol with level
HIDDEN
? for
WARNING
and
ERROR
you can do this:
Copy code
@Deprecated("w", level = DeprecationLevel.WARNING)
val w = "w"

@Deprecated("e", level = DeprecationLevel.ERROR)
val e = "e"

@Deprecated("h", level = DeprecationLevel.HIDDEN)
val h = "h"

println(@Suppress("DEPRECATION") w)
println(@Suppress("DEPRECATION_ERROR") e)
println(@Suppress("?? what goes here ??") h)
z
Hidden is hidden, you can no longer access that declaration from source code. There’s no way to suppress it like the others. Only existing code that’s already compiled to binary (assuming you’re on the JVM, this is bytecode/class files) can continue referencing and using it.
l
Hm, how do you then deprecate parts of a library with level hidden that depend on each other?
z
Interesting question - one thing you could do is move the implementation that you still want to be able to call into newly created private / internal methods, and have the deprecated (hidden) declarations call into those
l
And what about whole classes?
z
Not sure, perhaps you can just mark them internal instead of doing a HIDDEN deprecation in that case, but you’d have to check whether that still maintains binary compatibility - feels like it should
l
I will try, seems like it could work. Thanks!
Regarding the whole deprecated classes, currently you can use
@Suppress("DEPRECATION_ERROR")
in places where a deprecated-hidden class is still used in your API, but note that it is a suppression of an error and hence there are no guarantees that it will continue to work this way (see KT-24783). However, if we change how Suppress works, we'll still provide some other way to suppress deprecation errors.
472 Views