I wrote the following code in my application. ( office work )
@Override
public List<Outlet> getAllOutletForTouch() {
return outletDao.getOutlets();
}
This is the code one of my colleagues wrote.
@Override
public List<Outlet> getAllOutletsForMobile() {
List<Outlet> outletList = outletDao.getOutlets();
return outletList;
}
He created a new variable, assigned the values, and then returned the values; whereas I just returned the values directly calling the method. What is the convention for doing this?
As such there is no considerable performance difference in 2nd option as compare to the 1st, even on large scale, since as soon as the reference goes out of scope it will be GCed.
But it mostly about the coding style. IMO and as @Luiggi said in comments, 1st option is more readable but doesn't allow you to debug on return. If the return statement can throw exception that you might wanna debug, you need to go with 2nd option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With