Static variables in Java for a test oObject creator
- by stevebot
Hey,
I have something like the following
TestObjectCreator{
private static Person person;
private static Company company;
static {
person = new Person()
person.setName("Joe");
company = new Company();
company.setName("Apple");
}
public Person createTestPerson(){
return person;
}
public Person createTestCompany(){
return company;
}
}
By applying static{} what am I gaining? I assume the objects are singletons as a result. However, if I did the following:
Person person = TestObjectCreator.createTestPerson();
person.setName("Jill");
Person person2 = TestObjectCreator.createTestPerson();
would person2 be named Jill or Joe?