在Java中,是一个char []一个对象? [英] In Java, is a char[] an object?

查看:106
本文介绍了在Java中,是一个char []一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的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???

推荐答案

字符是一个原始的,但键入字符是一个对象

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());

输出:

字符

(<一个href=\"http://download.oracle.com/javase/6/docs/api/java/lang/Character.html#TYPE\"><$c$c>Character.TYPE通过对原始类字符访问类的另一种方法是参考 char.class

(Character.TYPE is a reference to the primitive class char. Another way to access that class is through char.class)

这篇关于在Java中,是一个char []一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆