Anyone know how to make this prettier or more eleg...
# codereview
j
Anyone know how to make this prettier or more elegant
Copy code
inline fun <reified T> Reader.readFirst(fieldId: Int): T {
    val field = this.getFirst(fieldId)
    val result: Any = when {
        Byte::class is T -> {
            field.asByte()
        }
        ByteArray::class is T -> {
            field.asByteArray()
        }
        Short::class is T -> {
            field.asShort()
        }
        Int::class is T -> {
            field.asInt()
        }
        Long::class is T -> {
            field.asLong()
        }
        Date::class is T -> {
            field.asDate()
        }
        UUID::class is T -> {
            field.asUUID()
        }
        String::class is T -> {
            field.asString()
        }
        else -> {
            throw Exception("Non supported type ${T::class}")
        }
    }

    return result as T
}