I was wondering whether there is a difference in initializing objects like ArrayList<> and stuff in field declaration or constructor.
Is there a difference in memory usage, performance or anything like that or is it completely the same?
Option 1:
class MyClass {
private List<String> strings = new ArrayList<String>();
}
Option 2:
class MyClass {
private List<String> strings;
public MyClass() {
strings = new ArrayList<String>();
}
}
It may be a stupid question, or a very basic one, but I like to build from the start, I like to understand all that I see.