数组中int[] a={};和int[] a=null;两者之间是有区别的。
int[] a={};{}中是有东西的,它在堆内存中开辟了空间,只是没有存东西。
int[] a=null;是在栈内存中开辟了4个字节,这块内存的名字叫a。
另外两者的输出结果也不同,前8者输出的是首地址,后者输出的是null值。
class yanzheng{
public static void main(String[] args){
int[] a=null;
System.out.println(a);
}
}
class yanzheng{
public static void main(String[] args){
int[] a={};
System.out.println(a);
}
}