可能重复:
How are Integer arrays stored internally, in the JVM?Java如何处理原始类型数组?
在C#,当创建一个新的数组,其是一个引用类型所以它把一个指针到堆栈和堆在对象本身。如果你创建这个数组与简单的原始类型,如int
,double
,等等。它的作用是把价值观正是它们被放置在堆,而不是指向在哪里存储它的内容的另一堆地址的指针。
所以,可以有人请解释这是如何发生在Java中? Java在数组中始终使用Integer
(引用类型),或将值类型视为C#呢?
int[] hello = new int[5];
hello[0] = 2; // C# put this value directly in same slot and doesn't
//create a wrapping object.
我知道一个叫做C#没有的Java环绕类型的东西。 C#有自动装箱但Int32
可以说不是一个引用类型,但ValueType
其中作为Integer
是相对于int
的对象。你可以使用Object o = 5;
来填充一个值,或者如果struct有一个父类,你也可以使用它来包装堆(装箱)。
http://stackoverflow.com/questions/76549/how-are-integer-arrays-stored-internally-in-the-jvm – theglauber
没有问题存在。然而,尽管C#中的'List'很好,但Java不喜欢这样。 –
harold
http://stackoverflow.com/questions/5564423/arrays-in-java-and-how-they-are-stored-in-memory – theglauber