• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there an optimization advantage in doing as shown in test2() below  RSS feed

 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any advantage from a performance standpoint in declaring an object outside of an interation loop before you go through and assign it references as the condition iterates (even if the collection is very large)? I would think there would be no performance advantage between test1 and test2 below but I want to be certain.

[ October 18, 2006: Message edited by: Rick Reumann ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No difference; in fact, the compiler will likely generate the identical bytecode (except for that null assignment.)
[ October 18, 2006: Message edited by: Ernest Friedman-Hill ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to find out what happens at the bytecode level, compile both pieces of code and disassemble them with javap:

javap -c MyClass
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!