ReplaceWith question

What is the syntax for using ReplaceWith for parameterized types?


@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?

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.

Looks like this issue: