ReplaceWith question


#1

What is the syntax for using ReplaceWith for parameterized types?

Example:

@Deprecated("Use ArrayList", ReplaceWith("ArrayList<E>(initialCapacity)"))
class MyCrappyList<E>(initialCapacity: Int = 16) : List<E> {

The <E> is just replaced with “<E>”, not the type it was before. Any suggestions?


#2

There are two bits here to refactor. One is the constructor. Replace this with a toplevel factory method (make sure to hide the constructor - make it private or add a dummy parameter - temporarily). You can make the factory create ArrayList (or mutableListOf(...)). The factory can then be inlined.

For replacing the actual type. Rename the class (without refactoring rename) and create a typealias the maps to ArrayList. Inline the typealias and tada you’ve changed over.


#3

Looks like this issue: https://youtrack.jetbrains.com/issue/KT-10094