English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

void function(val.getName(),val.gatAge()){ ////....} //In parameter im calling a function to get the value
or
passing the values od name,age like
void function(type name,type age){////} // In parameter im passing value

2006-11-07 20:02:47 · 4 answers · asked by gold_nat 1 in Computers & Internet Programming & Design

4 answers

Both have almost the same effect.

but it mostly depends on how efficient val.getName() works.
but if you using the same method to fetch the value and use it as a parameter,the first one would be better it will at least save a couple of object creations.

2006-11-07 20:07:31 · answer #1 · answered by srihari_reddy_s 6 · 0 0

This really depends on the usage. In general, there doesn't appear to be a difference *IF*, in either case, the caller or the object with function() must call the methods on the val object. The second version of function() which takes the actual value parameters would be more efficient if the caller already has the values or has direct access to them and does not need to first call getName() and getAge().

In code:
//If function() method is declared like this
void function(String name, long age){ ... }

//then calling from some other object...
functionOwner.function(val.getName(), val.getAge());
//is equivalent to
String name = val.getName();
long age = val.getAge();
functionOwner.function(name, age);

//but, if the calling object has direct access to the values,
//such as if the val object is calling function(), or the
//values have already been stored in variables (instant, static, or local)
//then this is more efficient
functionOwner.function(myName, myAge);

2006-11-09 11:13:14 · answer #2 · answered by vincentgl 5 · 0 0

The first one.

2006-11-08 04:07:00 · answer #3 · answered by jacksfullhouse 5 · 0 0

The second one is more efficient in terms of being able to quickly bug check or if others will be working or viewing the code it just makes more sense depending upon your variable names and all.
-NmD!

2006-11-08 04:10:03 · answer #4 · answered by NoMaD! 6 · 0 0

fedest.com, questions and answers