autoboxing

    5熱度

    2回答

    我的目標是優化我的應用程序代碼。我的代碼如下所示: int a = 10; Map<String , Integer> myMap = new TreeMap<>(); myMap.put("first" , new Integer(a)); //[FindBugs] Method com.abc.xyz.Test.main(String[]) invokes inefficient new

    4熱度

    1回答

    我遇到https://code.google.com/p/hamcrest/issues/detail?id=130爲Hamcrest匹配器添加一些糖語法。但是這個想法被Hamcrest的開發者拒絕了。 任何其他聰明的想法,通過避免長時間鍵入L,使測試更好的可讀性? @Test public void test1() { int actual = 1; assertThat(

    1熱度

    1回答

    Object[]可以存儲來自任何類的任何對象,因爲Java中的每個類都擴展爲java.lang.Object。 我不認爲原始圖像從Object延伸,爲什麼我們可以像下面那樣存儲它們? Object[] obj_arr = {1, 2, 1.2, 'a', false, new MyClass(), null}; 的問題是,爲什麼原語存儲在對象數組並沒有自動裝箱在上面的代碼中發生與否?

    0熱度

    1回答

    我剛將NetBeans從8.0更新到8.0.1,將我的JDK從1.8.0更新到1.8.0u20。我想很可能我的問題是由jdk-update造成的。 更新以前,我是能編譯這行代碼: int sum = myIntegerList.stream().reduce(0, (a, b) -> a + b, (c, d) -> c + d); 眼下這不會編譯任何更長的時間。 NetBeans告訴我「主類

    0熱度

    2回答

    我正在瀏覽一些java視頻教程,其中教師引用Double,Integer,Byte等作爲基元double,int,byte的助手類。但他們被認爲是包裝類,導致自動裝箱和拆箱,所以我無法弄清幫助類和包裝類之間的區別。

    0熱度

    1回答

    這是一個關於自動裝箱的實驗。主要思路是分別執行pop()和push()的安裝,並分別執行Stack和Stack<Integer>。下面的核心類: public class FixedCapcityStack<Item> { private final int cap; private Item[] arr; private int N; public Fix

    0熱度

    1回答

    這個簡單的代碼是拋NPE我不明白爲什麼? private Boolean isSangByJohnOrPaul() { final String sangBy = "harrison"; final Boolean result = sangBy.equals("lennon")?true :sangBy //throws NPE at this point

    2熱度

    2回答

    所以我知道你可以擁有對象流,即Stream<T>和專家原始流,例如IntStream,DoubleStream等。後者的好處之一是避免自動裝箱。 另外,如果我們以IntStream爲例,它具有專門的操作,如接受IntPredicate的過濾器。 我想知道是否有IntStream vs Stream<Integer>在哪一點上你節省了拳擊, intstream.filter(x -> x >= 50

    2熱度

    3回答

    請幫我把我的頭圍繞爲什麼這不起作用。 (這不是一個實際的問題,這是對OCPJP考試心理鍛鍊; Tibial。) public class ImplicitConversions { Integer iBoxed; short sPrimitive = (short)iBoxed; } //編譯器錯誤:不兼容的類型;需要:簡短,找到:整數 我假設編譯器試圖首先沒有(或之前)取消裝箱,而

    0熱度

    1回答

    下面的代碼會拋出一個NullPointerException但我不明白爲什麼,該對象不爲空。 public class A{ int GetValue() { return (true ? null : 0); } public static void main(String[] args) { A obj= new A();