I'm trying to create an abstract class with generic parameter which will have subclasses which should call methods without having to specify type parameters. I have this so far:
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")
I was wondering would it be possible to infer the type argument automatically?
Can I somehow rework myMethod? Note that I need to have T::class.java inside the method.