In netbeans I use to call a method that returns a value, but I am directly calling it where I have to pass a parameter to the function i.e. Function(getValue()) where getValuue() returns String. So what I want to know is that what is more efficient way to call this method whether should I assign value to a string first and then pass that value to parameter, as netbeans suggests me and shows a warning there, or calling it directly is good? I know code runs fine but keeping in mind the efficiency or rules of coding should I consider this thing or not? Or how badly can it effect if I ignore it?
In netbeans I use to call a method that returns a value, but I
Share
If you are only using that value once, then calling it directly where it is used as a parameter is fine.
In Java, this is fine:
Whereas in the following case:
It may be better to have a local variable so that you avoid calling a long running calculation twice. However, for simple
getValue()s, it really doesn’t matter.