I have an array with 4 objects, and only one of them is not null. I want to call a method, giving that variable as a param.
Block[] b = getIntersectingBlocks(e); // I get 4 Block variables, and only one of them is not null
// ...
Listener.myMethod(notNullBlock); // notNullBlock should be the block out of the array, that is not null
What is the fastest way of doing that, and avoiding if - else statements like this:
if (b[0] != null) {
Listener.myMethod(b[0]);
} else if (b[2] != null) {
Listener.myMethod(b[1]);
}
// ...
null? Also, an object cannot benull. An array variable (an array element) can referencenull.