Simple.
The first return
statement returns the item
only if the two nested conditions are satisfied.
Once your loop is over (aka the two nested conditions are not satisfied), the second return
statement triggers and returns null
.
In short, if your myBitmaps
array
or Collection
contains a Bitmap
that is not null
and whose id
equals the given id
for the method, that Bitmap
instance is returned.
Otherwise, null
is returned.
As fge mentions, a method has to fulfill all possible return paths (save for exceptional conditions).
If null
was not returned outside your loop, the code would not compile.
This would happen because if your conditions were not fulfilled, your loop would terminate without returning anything, and so would your method.