请看这个类,静态方法调用和输出。
public class OneThreadManyStaticCalls {
public static final Calculator calculator = new Calculator();
public static void main(String[] args) {
dummy(0, 1, 1);
dummy(0, 2, 2);
dummy(0, 3, 5);
dummy(0, 4, 44);
dummy(0, 5, 5);
}
public static void dummy(int a, int b, int expected) {
System.out.print(System.currentTimeMillis() + "\t");
if (calculator.add(a, b) == expected) {
System.out.println("OK");
} else {
System.err.println("NOK");
}
}
}
我得到了运行这个程序的不同(来自 System.out.print 的订单)输出。例子:
NOK
NOK
1342527389506 OK
1342527389506 OK
1342527389506 1342527389506 1342527389506 OK
你们谁能解释我(详细)为什么?提前致谢。sznury