Is this the intended behavior?
If you are checking out JavaDoc Response<T>you can read
@Nullable public T body () From the deserialized response body of a successful response.
Javadoc: response
It is body()not expected nullif the answer was successful. To test success, you have isSuccessful()which
true, () [200..300).
, @Nullable , null , . , .
IDE - , .
body() null lint .
response.body() , 1 .
. , body() , , .
T res1 = response.body(); // could be null
T res2 = response.body(); // ...maybe still null?
Lint - , , NPE. @Nullable, , null, , .
response.body() != null && response.body().getCar() != null
, , lint, .
, , null - null , lint .
CarResponseBody body = response.body(); // assign body() to a local variable
if (body != null && body.getCar() != null) { // variable is not null
CarResponse car = body.getCar(); // safe to access body, car is also not null
// everything is fine!
}
, ?
. @Nullable - , null, , null , lint NullPointerExceptions.
null, null , .
Car car = response.getBody();
if(car != null) {
}
/
, , , .
CarResponseBody body = response.body();
Car car = body.getCar()
, , *ResponseBody . , . Jake Wharton
RxJava Retrofit, . , , Rx-.