1. JUnit的TestCase的setUp()和tearDown()是每个testXXX方面运行的时候都要执行的!这个我第一次听说,我以前一直以为是整个TestCase执行之前和之后执行的。
但我们很多时候还是希望整个TestCase有个初始化和反初始化,这方面可参见:http://www.blogjava.net/iamtin/archive/2006/11/17/81802.html
2. Math.abs()方法可能算出负数!这个更是让人大跌眼镜,不过这个是真的,因为:
Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE。因为32位整数的最小值是-2^31,但最大值是+2^31-1,所以对于负数的最小值,找不到正数和它对应了,如果用0 - Integer.MIN_VALUE,会出现整数上溢错误。
3. 解决Eclipse项目Build Path循环引用问题。Eclipse在编译的时候说:“A cycle was detected in the build path of project: XXX”。办法是:Eclipse Menu -> Window -> Preferences... -> Java -> Compiler -> Building -> Building path problems -> Circular dependencies -> 将Error改成Warning。