Is there a difference in class and local instantiation when the first one is not obligatory (usually when i can finalize them)? Is there a "rule" i should follow?
I have developed the habit to always instantiate other classes using class instantiation and i don't really know if this is bad.
public class aService {
private final SomeClass someClass = new SomeClass();
public void someMethod() {
someClass.doSomething();
}
}
// or
public class aService {
public void someMethod() {
SomeClass someClass = new SomeClass();
someThing.doSomething();
}
}