Lubos Mudrak
Lubos Mudrak

Reputation: 680

Kotlin replaceWith an invoke operator

I have an interface where I would like to notify users to use invoke operator instead of oldFunction.

interface SomeInterface {

  operator fun invoke(param: A)

  @Deprecated("Old stuff", ReplaceWith("invoke(param)"))
  fun oldFunction(param: A)

}

This currently works, but it replaces the oldFunction with invoke call in place. What I would like is to have it replace the invoke call with invoke operator (). Is this possible ? I'm using Android Studio 3.5

Upvotes: 4

Views: 1166

Answers (1)

IlyaMuravjov
IlyaMuravjov

Reputation: 2492

You can do it like this:

@Deprecated("Old stuff", ReplaceWith("this(param)"))
fun oldFunction(param: A)

Upvotes: 3

Related Questions