在Java中,char[]是一个对象吗?
我是 Java 新手,但如果我理解正确的话, char 是一个原语。
执行 char temp 和 temp.hashCode() 不会编译,但执行 char[] temp2 = new char[2] 和 temp2.hashCode() 将编译并执行。
这是否意味着 char[] 是一个对象???
I'm new to Java but if I understand correctly, a char is a primitive.
Doing char temp and temp.hashCode() won't compile but doing a char[] temp2 = new char[2] and temp2.hashCode() will compile and execute.
Does this mean somehow a char[] is an object???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
char
是一个原语,但char
类型的数组是一个对象,一种判断方法是动态实例化它:
输出:
(
Character.TYPE
是对原始类char
的引用。访问该类的另一种方法是通过char.class
)a
char
is a primitive, but an array of typechar
is an objectone way to tell is by dynamically instantiating it:
Output:
(
Character.TYPE
is a reference to the primitive classchar
. Another way to access that class is throughchar.class
)是的。所有数组都是对象,甚至是原始类型的数组。
Yes. All arrays are objects, even arrays of primitive types.
是的,Java 中所有的数组都是对象。
Yes, all arrays are Objects in Java.
是的,每种类型的每个数组都是一个对象。
Yes, every Array of every type is an object.
是的,数组是java中的对象。
Yes arrays are objects in java.
数组不仅仅是几种基本类型,它还有一个“长度”字段。原始类型没有字段。数组与原始类型不同的另一件事是它们是引用,因此必须进行垃圾收集。
An array isn't just several primitive types, it also has a "length" field. Primitive types don't have fields. Another thing that sets arrays appart from primitive types is they are references and thus have to be garbage collected.