can anyone point me to how to use the `Deprecated`...
# getting-started
j
can anyone point me to how to use the
Deprecated
annotation
ReplaceWith
when the argument is a receiver function type?
Copy code
@Deprecated
fun factory(initializer: Builder.() -> Unit): Type = Builder().apply(initializer).build()
it keeps bringing in the deprecated builder even when i have added the imports argument to
Deprecated
j
Could you please show an example of what you want the users to use instead of the function?
j
I really just want to do a package move, so same name, args, return, etc
same thing with extension functions too, i just want them to move to a different package
Copy code
public fun URI.modified(): URI = URI(this.toString() + "/example")
Copy code
fun main() {
// stays the same but the import should change
val modified = URI("<example://ex>").modified()
}
@Joffrey
j
Oh sorry I missed your messages, for the extension function you can use
this
in the replacement string:
Copy code
package com.example.somepackage

@Deprecated(
    message = "",
    replaceWith = ReplaceWith("this.modified()", imports = ["com.example.otherpackage.modified"]),
)
fun URI.modified(): URI = URI(this.toString() + "/example")
And for the initial function you can use:
Copy code
@Deprecated(
    message = "",
    replaceWith = ReplaceWith("factory(initializer)", imports = ["com.example.otherpackage.factory"]),
)
fun factory(initializer: Builder.() -> Unit): MyType = Builder().apply(initializer).build()
All of this is of course assuming the same function exists in another package
j
awesome thank you! i'll try on monday and let you know how it goes!
👍 1
this doesn't work if anyone checks this thread FYI
🤔 1
j
So FYI the
ReplaceWith
in this case does work, but it transforms the lambda into an anonymous function. Not very beautiful, but at least the code is correct.