fun convertPrimitiveType(type: Type): Class<*>? {
return when (type) {
java.lang.Void::class.java -> kotlin.Unit::class.java
java.lang.Float::class.java -> kotlin.Float::class.java
java.lang.Short::class.java -> kotlin.Short::class.java
java.lang.Double::class.java -> kotlin.Double::class.java
java.lang.Long::class.java -> kotlin.Long::class.java
java.lang.Integer::class.java -> kotlin.Int::class.java
java.lang.Byte::class.java -> kotlin.Byte::class.java
java.lang.Character::class.java -> kotlin.Char::class.java
else -> {
if (type is Class<*> && type.isPrimitive) {
when (type.name) {
"void" -> kotlin.Unit::class.java
"float" -> kotlin.Float::class.java
"short" -> kotlin.Short::class.java
"double" -> kotlin.Double::class.java
"long" -> kotlin.Long::class.java
"int" -> kotlin.Int::class.java
"byte" -> kotlin.Byte::class.java
"char" -> kotlin.Char::class.java
else -> null
}
} else {
null
}
}
}
}
2020-03-12
网友评论