问题描述
我有一个第三方服务,它公开了一个具体化的扩展函数。我想把这个服务包装成一个接口实现对,以便于测试和封装。
问题是我不能在我的应用程序中使用这个函数,因为编译器告诉我:
Cannot use 'T' as reified type parameter. Use a class instead.
结构如下:
interface ThirdPartyService
inline fun <reified T> ThirdPartyService.execute(): T
interface Wrapper {
fun <T> execute(): T
}
class WrapperImpl(private val thirdPartyService: ThirdPartyService) : Wrapper {
override fun <T> execute(): T =
thirdPartyService.execute()
}
在这种情况下,调用 thirdPartyService.execute()
会导致我上面提到的编译器问题。
有什么办法可以解决这个问题吗?这个 Use a class instead.
实际上是什么意思?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)