should we try to minimize declaring instance variables? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

should we try to minimize declaring instance variables?

is declaring instance variable instead of local variable effects efficiency in java app?

16th Aug 2018, 3:47 AM
sal sal
sal sal - avatar
1 Answer
0
Its based on your use case. If you need to use a field that should be globally accessible then create an instance field. If you need to create a local field that will be used within the scope of a method then use that. Try not to recreate large objects as local variabled. IE instantiating a large object every time you run a method.
17th Aug 2018, 8:30 AM
John
John - avatar