open class BaseRepository { /** * IO中处理请求 */ suspend fun <T> requestResponse(requestCall: suspend () -> BaseResponse<T>?): T? { val response = withContext(Dispatchers.IO) { withTimeout(10 * 1000) { requestCall() } } ?: return null if (response.isFailed()) { throw ApiException(response.errorCode, response.errorMsg) } return response.data } }
class LoginRepository : BaseRepository() { /** * 登录 * @param username 用户名 * @param password 密码 */ suspend fun login(username: String, password: String): User? { return requestResponse { ApiManager.api.login(username,password) } }
}
调用 requestResponse 报 Type mismatch: inferred type is com.filing.kotlindemo.repository.repository.BaseResponse<User?>? but com.filing.kotlindemo.repository.response.BaseResponse<TypeVariable(T)>? was expected 如何修改????