Reputation: 2531
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()
}
Upvotes: 35
Views: 24135
Reputation: 23312
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.
Upvotes: 60