【发布时间】:2020-10-31 15:08:18
【问题描述】:
下面的代码显示了错误。类型推断失败。预期类型不匹配必需:Response<BaseResponse<Any>>! 找到:Response<BaseResponse<RetriveUserInfoResponse>!>!
`when`( mockIOnboardingService.validateCustomerIdentity(customerType.toLowerCase(), ValidateCustomerRequest(customerId, documentType, "243546", tyc)))
.thenReturn(Response.success(BaseResponse(payload = RetriveUserInfoResponse("+5689765432")))) //--> Here the error
这是 validateCustomerIdentity 方法
@POST(ApiConstants.bffOnboardingPath + ApiConstants.pathRetriveUserInfo)
suspend fun validateCustomerIdentity(
@Header(ApiConstants.headerXflowService) customerType : String,
@Body body: ValidateCustomerRequest
): Response<BaseResponse<Any>>
如您所见,它返回BaseResponse<Any>。为什么 Android Studio 将 BaseResponse<RetriveUserInfoResponse>! 显示为错误
这是 RetrieveUserInfoResponse 数据类
data class RetriveUserInfoResponse(
@SerializedName("phone")
val phone: String
)
【问题讨论】:
标签: kotlin generics covariance