下面代碼陣列零長度的在Java
public class Example {
static int[] member;
public static void main(String[] args) {
int[] ic = new int[0];
if (ic == null){
System.out.println("ic is null");
}
System.out.println(ic); // [[email protected]
if(member == null){
System.out.println("member is null");
}
}
}
很明顯,元件不能零長度數組加入。
ic
指的是什麼,如果ic
不是null
?
根據下圖,指向內存位置659e0bfd
(它是空的)是ic
?
根據上述代碼在內存地址爲'659e0bfd'的空數組? – overexchange
@proxchange爲數組輸出的哈希碼可能與內存地址有關,但它不是內存地址本身。請參閱http://stackoverflow.com/questions/2237720/what-is-an-objects-hash-code-if-hashcode-is-not-overridden –
@overchange是'obj1 == obj2'檢查兩個變量參考內存中的同一個對象。 Java沒有獲取內存地址的機制。 – manouti