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 
1
  • the reason of deprecation is here Commented Feb 10, 2020 at 17:08

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

getDeclaredConstructor (note the missing s) should work... it accepts a variable amount of parameter types...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.