Results 1 to 3 of 3
- 03-03-2010, 12:59 AM #1
some basic advice on using methods please
to put it very simply,
if i call getWidth(); and wish to use it 3, 4 or 50 times within a block or a class, is it better to call it once and assign it to variable, and then use the variable or call it every-time I need it?
Similarly , if I have a method to calculate some complex expression, is it better to call it every-time I need it or call it once and assign it to a variable?
Are there a cases for both?
thanks in advance..
Sonny:p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts
- 03-03-2010, 01:02 AM #2Senior Member
- Join Date
- Dec 2009
- Belgrade, Serbia
- Rep Power
Assign to variable.
Why calculating every time if result is time same - waste of time
- 03-03-2010, 01:38 AM #3
- By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-17-2012, 12:00 AM
- By azlynn in forum New To JavaReplies: 2Last Post: 12-10-2009, 03:47 AM
- By butterhero in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-18-2009, 12:40 PM
- By awebbtt in forum New To JavaReplies: 3Last Post: 02-02-2009, 08:23 PM
- By dineshjf in forum Advanced JavaReplies: 18Last Post: 01-09-2009, 04:17 AM