I just wonder if there is a good reason or practice of when to use != null
instead of instanceof
to check if something is null.
Is a bad practice to test if something is null with instanceof
?
For example:
View view = ((Activity) context).findViewById(viewID);
if (view instanceof View) {
listener.onView(view, viewID);
}
or
View view = ((Activity) context).findViewById(viewID);
if (view != null) {
listener.onView(view, viewID);
}
Shouldn't it works just as same?