I want to rename a Kotlin type, leaving a deprecated typealias to allow existing code to compile.
typealias TestContext<F> = ContextBuilder<F>
@Deprecated("TestContext is now ContextBuilder",
replaceWith = ReplaceWith("ContextBuilder<F>"))
leads to TextContext<Unit>
being replaced with ContextBuilder<F>
@Deprecated("TestContext is now ContextBuilder",
replaceWith = ReplaceWith("ContextBuilder"))
leads to TextContext<Unit>
being replaced with ContextBuilder
How can I write the replaceWith expression so that IntelliJ replaces TextContext<Unit>
with ContextBuilder<Unit>
?
We can make generic variable using this kind of syntax: "val destinationActivity: Class<*>". Main part is "*".
Kotlin generic example When we call the generic method <T>printValue(list: ArrayList<T>) using printValue(stringList), the type T of method <T>printValue(list: ArrayList<T>)will be replaced by String type.
There are no direct ways to do this in Kotlin. In order to check the generic type, we need to create an instance of the generic class<T> and then we can compare the same with our class.
"Out" keyword is extensively used in Kotlin generics. Its signature looks like this − List<out T> When a type parameter T of a class C is declared out, then C can safely be a super type of C<Derived>. That means, a Number type List can contain double, integer type list.
This is possible now! The ReplaceWith
intention saves generic type arguments from Kotlin plugin v1.3.40 on (see change log).
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