编写自定义Retrofit适配器的通用问题

在过去,我已经编写了基于此代码的自定义error handling适配器进行改进: https : //github.com/square/retrofit/blob/master/samples/src/main/java/com/example/retrofit/ErrorHandlingAdapter.java

哪些工作真的很好。

我现在正在Kotlin编写我们的新应用程序,当转换代码时,呼叫适配器工厂给我一个错误,特别是在get函数中。 它转换成这样的样子:

 override fun get(returnType: Type, annotations: Array, retrofit: Retrofit): CallAdapter? { if (CallAdapter.Factory.getRawType(returnType) != MyCall::class) { return null } if (returnType !is ParameterizedType) { throw IllegalStateException( "MyCall must have generic type (eg, MyCall)") } val responseType = CallAdapter.Factory.getParameterUpperBound(0, returnType) val callbackExecutor = retrofit.callbackExecutor() return ErrorHandlingCallAdapter(responseType, callbackExecutor). \\This line produces an error } 

错误说Projections are not allowed on type arguments of functions and properties

我已经尝试了几种方法来提取返回types的参数,因为到最后我知道我正在处理MyCall

然而,我试过的每一个方法都不能给我一个T的版本,我可以用它替换它。 这是令人沮丧的,因为只要types从调用适配器返回,T的types是相当不相关的。

我知道我可以将它作为一个Java类导入并以此方式使用,但是我的目标是尽可能在Kotlin中编写所有内容。 在Kotlin中可以做到这一点吗?