What is the Convention for returning a value?

coding-style, conventions, java

Solution

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.

Problem

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?

Original source

Related problems