• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

use of temporary variable inside method

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a doubt in using a temporary variable defined inside a method.
I am defining a temporay String object inside my method and initializing with the value returned from a called function and then again I am using it as parameter in my another calling function. Will be there any performance issues?? Whats the best of doing it. Should I use temporary variable or not?
Example ::

String temp = object.generateMapping(map);
object1.addValues(temp);

any suggestions are welcomed
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Believe me you really do not need to think about it!!!
Just go ahead and do what you think will increase code readability.

Remember - "Premature optimization is a root of all evils"
 
Saloon Keeper
Posts: 28720
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The trip from source to final executable is fairly complex. It's not uncommon for 7 layers or more of processing to pass over the code as it makes its way from human-readable source to lexical token streams to abstract syntax trees and on down the line.

As part of this process, a lot of things get pushed up, pulled down, shifted around, created and destroyed. Temporary variables are one of the prime targets. So don't try to optimize code based on temporary variable usage - it's pointless.

The only exception I'll make is that if you are running with optimization switched off, some artifacts may remain to assist a debugger when it wants to print those intermediate values. However, if performance at the code level is critical, you should turn optimization on.
 
Naty wills
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the Suggestions
reply
    Bookmark Topic Watch Topic
  • New Topic