kotlin 这个体验也太好了
// 获得T.class
inline fun <reified T> classOf() = T::class.java
//获得 T object
inline fun <reified T> instanceOf() = T::class.java.newInstance()
fun main() {
var clazz = classOf<String>()
var str = instanceOf<String>()
}
kotlin 这个体验也太好了
// 获得T.class
inline fun <reified T> classOf() = T::class.java
//获得 T object
inline fun <reified T> instanceOf() = T::class.java.newInstance()
fun main() {
var clazz = classOf<String>()
var str = instanceOf<String>()
}
本文标题:kotlin 获得泛型类及泛型实例化
本文链接:https://www.haomeiwen.com/subject/acprmhtx.html
网友评论