私はうまく動作するJavaクラスファイルを持っていますが、私がKotlinに変換すると問題があります。ここではJavaのバージョンkotlinに変換されたjavaクラスファイルがコンパイルエラーを起こす
public class CallbackWrapper<T> implements Callback<T> {
private Wrapper<T> wrapper;
public CallbackWrapper(Wrapper<T> wrapper) {
this.wrapper = wrapper;
}
public void onFailure(Call<T> call, Throwable t) {
wrapper.onResult(t, null);
}
public void onResponse(Call<T> call, Response<T> response) {
wrapper.onResult(null, response);
}
public interface Wrapper<T> {
void onResult(@Nullable Throwable t, @Nullable Response<T> response);
}
}
があり、これは、私は何の問題もなく、このクラスを使用している方法です...
request.enqueue(CallbackWrapper<RegisterResponse> { throwable, response ->
response?.let { callBack.onResponse(response.body() ?: RegisterResponse()) }
throwable?.let { callBack.onFailed(throwable.message!!) }
})
そしてここでは、Kotlinのバージョンは
class CallbackWrapper<T>(private val wrapper: CallbackWrapper.Wrapper<T>) : Callback<T> {
override fun onFailure(call: Call<T>, t: Throwable) {
wrapper.onResult(t, null)
}
override fun onResponse(call: Call<T>, response: Response<T>) {
wrapper.onResult(null, response)
}
interface Wrapper<T> {
fun onResult(t: Throwable?, response: Response<T>?)
}
}
変換した後で問題は、Kotlinに変換した後で、私がこのクラスを使用しているコードブロックが機能していないことです。私はそれらの違いは何か分かりません。ここで
は、あなたが私の知る限り、あなたのコードには2つの問題があり、エラーログ
Error:(17, 63) Type mismatch: inferred type is (???, ???) -> [ERROR :<ERROR FUNCTION RETURN TYPE>] but CallbackWrapper.Wrapper<RegisterResponse> was expected
Error:(17, 65) Cannot infer a type for this parameter. Please specify it explicitly.
Error:(17, 76) Cannot infer a type for this parameter. Please specify it explicitly.