由於某種方法,我得到一個Long值。現在,當我想將該數字加1時,編譯器會提醒我有關正在裝箱/拆箱以執行總和的值。是否可以在沒有裝箱/拆箱的情況下添加包裝數字?
public Long getLongValue() {return new Long(5L);}
// ...
Long val = getLongValue();
val++; // Warning: The expression of type Long is unboxed into long
val = val + 1L; // Warning: The expression of type Long is unboxed into long
由於Long類似乎沒有「add」方法,有沒有什麼辦法可以避免這種自動裝箱行爲?
(注:我知道我可以只@SuppressWarnings或手動盒/拆箱的值,而不是使用自動裝箱功能我試圖實現是完全避免裝箱/拆箱)