sự khác biệt giữa làm điều này là gì:Sự khác biệt giữa instantiating trong trường và instantiating trong constructor là gì?
public class SomeClass {
SomeObject obj = new SomeObject();
//rest of the code
}
và điều này
public class SomeClass {
SomeObject obj;
public SomeClass(){
obj = new SomeObject();
}
//rest of the code
}
bản sao của http://stackoverflow.com/questions/1568722/on-the-thread-safety-of-instance-variable-initialization –