我的IDE給Integer提供了一個不必要的裝箱警告。我在Netbeans中得到了不必要的裝箱整數
// Custom
double[] Cvalues = {18,1,0,0,17};
methodParams.put(Integer.valueOf(this.getCustom()), Cvalues);
我的IDE給Integer提供了一個不必要的裝箱警告。我在Netbeans中得到了不必要的裝箱整數
// Custom
double[] Cvalues = {18,1,0,0,17};
methodParams.put(Integer.valueOf(this.getCustom()), Cvalues);
如果你有一個Map<Integer, Object> myMap
和你做這樣的事情:因爲與Integer類的包裝
Map<Integer, Object> myMap = new HashMap<>();
myMap.put(Integer.valueOf(1), "A");
myMap.put(Integer.valueOf(10), "B");
myMap.put(Integer.valueOf(13), "C");
那麼編譯器會生成警告是沒有必要的......
它將足以做到:
myMap.put(1, "A");
myMap.put(10, "B");
myMap.put(13, "C");
你的情況
methodParams.put(Integer.valueOf(this.getCustom()), Cvalues);
看起來像getCustom()
方法正在返回的整數原始使原始不必要的拳擊/包裝。
只是做:
methodParams.put(getCustom(), Cvalues);
閱讀關於自動裝箱了Java教程,它應該閱讀教程「Integer.valueOf(this.getCustom())」是不必要的,只需要打一個電話後是顯而易見的「this.getCustom()」將刪除警告。
https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html
爲什麼你需要這樣的:'Integer.valueOf(this.getCustom())'?只需使用'getCustom()'。 –
問題是什麼?你只是告訴我們你的IDE告訴你,你正在做不必要的拳擊。你認爲你的IDE在騙你嗎?實際上你在做不必要的拳擊。 – Michael
我的IDE抱怨缺少分號。咄! –