Static variables in Java for a test oObject creator
        Posted  
        
            by stevebot
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by stevebot
        
        
        
        Published on 2010-05-17T19:06:12Z
        Indexed on 
            2010/05/17
            19:10 UTC
        
        
        Read the original article
        Hit count: 399
        
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?
© Stack Overflow or respective owner