HttpServletRequest request; int userID = (new UserUtil(connection)).findByUserName(request.getRemoteUser()).getUserID();
I know that is not the cleanest code to read, but I have the idea that is efficient, because there are not new references created on the heap, then the anonymous object is ready for garbage collection. Now if I do something like:
HttpServletRequest UserUtil userUtil = new UserUtil(connection); String userName = request.getRemoteUser(); User user = userUtil.findByUserName(userName); int userID = user.getUserID();
will be as efficient that the code describe first?
I agree with Steve and Stefan - don't worry about it, just use the one that you find easier to read.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jul 11, 2001
By the way, all objects are "anonymous" in the sense that they don't have names. The only things having names are the reference variables (which an object can have an arbitrary number being referenced by).