• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory usage -- which is better?

 
Kev Adams
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across some code today that looks like this:



Would it not be better, not only for readability, but for memory usage to do it like this:



My thinking is that Java has to create a temporary memory space to hold whatever is returned by getObjA().getObjB().getObjC() each time.

Is that correct?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Performance / memory use is not the issue here, the ability to debug and maintain the code is.

If any of those compound statements threw a NullPointerException, where would you look?

"Premature optimization is the root of all evil"

Bill
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic