All Downloads are FREE. Search and download functionalities are using the official Maven repository.

utils.reflect.kt Maven / Gradle / Ivy

There is a newer version: 0.0.4-dev-1
Show newest version
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