最近解決的3個Java問題

來源:互聯網
上載者:User

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。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.