I wrote this code:
@Deprecated("Old stuff", ReplaceWith("test2"))
fun test1(i: Int) {
println("old Int = $i")
}
fun test2(i: Int) {
println("new Int = $i")
}
fun main(args: Array<String>) {
test1(3)
}
and for some reason when I press Alt+Enter and click "Replace with test2
", the method test1
disappears and doesn't get replaced, what am I doing wrong?
Edit:
It does work for classes though:
@Deprecated("Old stuff", ReplaceWith("Test2"))
class Test1
class Test2
fun main(args: Array<String>) {
val a = Test1()
}
To help removing deprecated API gradually, the property level could be used. Usually a gradual phase-out goes through the "warning", then "error", then "hidden" or "removed" stages: First and by default, DeprecationLevel. WARNING is used to notify API consumers, but not to break their compilation or runtime usages.
Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.
You need to tell how it needs to be replaced exactly... While I do not know why it was just completely deleted, I will show you what I mean instead:
If you would use the following instead:
@Deprecated("Old stuff", ReplaceWith("test2(i)"))
it will replace your test1(5)
call to test2(5)
correctly.
Note also that sometimes you may want to add the package name also if it isn't that clear which replacement should take place, e.g.:
@Deprecated("Old stuff", ReplaceWith("org.example.test2(i)"))
// or just use:
@Deprecated("Old stuff", ReplaceWith("test2(i)", /* here come the imports */ "org.example.test2"))
You can also use static values in the replacement in case that is what you need.
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