utils.reflect.kt Maven / Gradle / Ivy
package com.elouyi.bely.utils
import kotlin.jvm.Throws
import kotlin.reflect.KClass
/*@Throws(Exception::class)
fun newInstance(t: T,vararg params: Any? = arrayOf()): R where T: KClass {
}*/
fun T.newInstance(vararg params: Any? = arrayOf()): R where T: KClass {
try {
objectInstance?.let {
return it
}
} catch (e: Exception){}
for (constructor in constructors) {
try {
return constructor.call(*params)
} catch (e: Exception) {}
}
throw Exception("无法实例化${qualifiedName}")
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy