https://kotlinlang.org logo
#library-development
Title
# library-development
l

Lukellmann

07/19/2022, 1:12 PM
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

zsmb

07/19/2022, 2:12 PM
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

Lukellmann

07/19/2022, 2:13 PM
Hm, how do you then deprecate parts of a library with level hidden that depend on each other?
z

zsmb

07/19/2022, 2:16 PM
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

Lukellmann

07/19/2022, 2:18 PM
And what about whole classes?
z

zsmb

07/19/2022, 2:19 PM
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

Lukellmann

07/19/2022, 2:23 PM
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.
196 Views