3
inline fun <reified T> blah(block: T.() -> Unit): Something {
    request = T::class.java.newInstance()

that newInstance() is deprecated, usually when you go to the source, it says why it's deprecated and what the alternative is, but this time i'm only seeing:

/** @deprecated */
@CallerSensitive
@Deprecated(
    since = "9"
)
public T newInstance() throws InstantiationException, IllegalAccessException {
    // ...
}

What is the new non-deprecated way to create an instance of a reified type in Kotlin?

Update: More information as requested:

JDK Version: 11 (not Android, just pure JVM)
Kotlin Version:1.3.61 
Roland
  • 22,259
  • 4
  • 57
  • 84
Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137
  • the reason of deprecation is [here](https://stackoverflow.com/questions/195321/why-is-class-newinstance-evil/53014482#53014482) – Eugene Feb 10 '20 at 17:08

1 Answers1

3

Actually this comes from Java itself. The appropriate replacement is:

T::class.java.getDeclaredConstructor().newInstance()

You can also check the Class.newInstance()-Javadoc which states that too.

Roland
  • 22,259
  • 4
  • 57
  • 84
  • 1
    `getDeclaredConstructor` (note the missing `s`) should work... it accepts a variable amount of parameter types... – Roland Feb 10 '20 at 09:01