java - new Obj, always or sometimes? -
should make new objects out of in java if know use one?
obj = new obj(); obj.method(); or just
classofobject.method(); why should bother creation of new obj in situation this?
classofobject.method() works if method static.
having said that, if class represents "thing", user, car, whatever, should make method non-static , use new make object , invoke information on it.
if class container methods don't have objects themselves, e.g. utils class stringutils, can use static methods, e.g. stringutils.touppercase(), , happy it.
Comments
Post a Comment