问题描述
我是新来的Java,但如果我理解正确的话,一个char是原始的。
I'm new to Java but if I understand correctly, a char is a primitive.
做炭温度和temp.hash code()将无法编译,但做一个char [] = TEMP2新的char [2]和temp2.hash code()将编译和执行。
Doing char temp and temp.hashCode() won't compile but doing a char[] temp2 = new char[2] and temp2.hashCode() will compile and execute.
这是否意味着在某种程度上一个char []是一个对象???
Does this mean somehow a char[] is an object???
推荐答案
在字符
是一个原始的,但键入字符数组code>是一个对象
a char
is a primitive, but an array of type char
is an object
告诉一种方法是通过动态实例化:
one way to tell is by dynamically instantiating it:
final Object charArray = Array.newInstance(Character.TYPE, 5);
System.out.println(charArray.getClass().getComponentType());
输出:
字符
(<$c$c>Character.TYPE$c$c>通过对原始类字符
访问类的另一种方法是参考 char.class
)
(Character.TYPE
is a reference to the primitive class char
. Another way to access that class is through char.class
)
这篇关于在Java中,是一个char []一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!