While reviewing some java code, I've run into a piece of code as this:
Integer initialQ = someObject.getInitialQ();
Integer finalQ = null;
BigDecimal factor = calculateFactor(initialQ, finalQ);
if (finalQ.compareTo(initialQ) != 0){
//do something
}
finalQ
is modified in the method calculateFactor.
Eclipse gives me a "Null pointer access: The variable idUnidadFinal can only be null at this location" warning on if (finalQ...)
. I understand that since we need to get factor
returned from the method, the only way to modify finalQ
is to pass it as reference. But, is this the correct, accepted way of doing it?
The only alternative I can think of is to design a new class which has finalQ
and factor
as fields, but looks unnecessarily complicated.