当Animal类覆盖Zoo类时,是否可以返回泛型T的实例?
classInstance<T>() returns a type mismatch; required class<T> found T.
private inline fun <reified Eat : T> classInstance(): Eat = Eat::class.java.newInstance()
abstract class Animal<Result> {
abstract fun bark(): Class<Result>
}
open class Zoo<T>(protected var listener: RequestListener<T>?) : Callback<T>, Animal<T>() {
override fun bark(): Class<T> = classInstance<T>()
}
bark()
函数将用于以下目的:
Gson().fromJson(inputStreamReaderResult, bark())
,其中bark()
必须是Class类型