为什么类型参数T
在下面(取自https://gist.github.com/quangIO/a623b5caa53c703e252d858f7a806919)需要Any
的界线?
private class Json<out T : Any>(private val klass: Class<T>, private val jsonMapper: ObjectMapper) : ColumnType() {
override fun valueFromDB(value: Any): Any {
value as PGobject
return try {
jsonMapper.readValue(value.value, klass)
} catch (e: Exception) {
e.printStackTrace()
throw RuntimeException("Can't parse JSON: $value")
}
}
}