package com.dingwang.Test;
import java.util.ArrayList;
import java.util.List;
/**
* 类TestStatic.java的实现描述:TODO 类实现描述
*
* @author eden.ding 2016年4月20日 下午9:05:04
*/
public class TestStatic {
private static List<String> list = new ArrayList<String>();
static {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
for (int i = 0; i < 100; i++) {
list.add(String.valueOf(i));
}
}
public int getListSize() {
return list.size();
}
}
package com.dingwang.Test;
import org.junit.Test;
/**
* 类TestStaticRun.java的实现描述:TODO 类实现描述
*
* @author eden.ding 2016年4月20日 下午9:09:19
*/
public class TestStaticRun {
@Test
public void testRun() {
TestStatic t = new TestStatic();
System.out.println(t.getListSize());
}
}
输出结果:<strong>100</strong>
结论:创建实例时,先走static块,然后调用构造函数