我正在try 创建一个带有泛型参数的抽象类,该类将具有应该调用方法without having to specify type parameters的子类. 到目前为止,我有这样的 idea :
abstract class AbstractClass<T : Any> @Autowired constructor(protected val delegate: MyService) {
inline fun <T: Any> myMethod(param: Any): T? {
return delegate.myMethod(param).`as`(T::class.java)
}
}
And implementation:
class TesterWork @Autowired constructor(delegate: MyService) : AbstractClass<Tester>(delegate) {
}
Now when calling myMethod
I have to specify the type argument:
testerWork.myMethod<Tester>("test")
我想知道是否有可能自动推断类型参数?