java 数组

1 数组是引用类型

 

2 java虚拟机在装入数组时,会根据数组元素的类型以及数组维度创建对应的Class对象,数组元素的类型和维度唯一确认了数组类的Class对象,比如下面的代码:

    public static void main (String[] args) {
        int[] a = new int[5];
        System.out.println(a);
        String[] b = new String[5];
        System.out.println(b);
        ForkJoinDemo[] c = new ForkJoinDemo[5];
        System.out.println(c);
        String[][] aa = new String[3][];
        aa[0] = new String[3];
        System.out.println(aa[0]);
        ForkJoinDemo[][] cc = new ForkJoinDemo[3][];
        cc[0] = new ForkJoinDemo[3];
        System.out.println(cc);
        System.out.println(cc[0]);
    }

 打印结果:

 

[I@136a43c
[Ljava.lang.String;@589e56
[Lcom.malone.threadCurr.ForkJoinDemo;@3411a
[Ljava.lang.String;@edf3f6
[[Lcom.malone.threadCurr.ForkJoinDemo;@2bc3f5
[Lcom.malone.threadCurr.ForkJoinDemo;@14e3f41

 打印结果前半段为class的名称;由此可以知道虚拟机会为根据数组元素的类型和数组的维度创建Class对象,类命名规则为:

1 根据维度决定[的个数,维度为1则以一个[开头,为2以两个[[开头,以此类推

2 如果数组元素的类型为基础数据类型,比如int, long 则以首字母大写跟在[后面

3 如果数组元素类型为引用类型,则在[后面加一个大写的L然后再引用类的名称

 

虚拟机根据数组元素类型和维度来唯一创建类:

public class ForkJoinDemo {
    public static void main (String[] args) {
        int[] a = new int[5];
        System.out.println(a.getClass());
        int[] b = new int[100];
        System.out.println(b.getClass());
        System.out.println(a.getClass() == b.getClass());

        ForkJoinDemo[] c = new ForkJoinDemo[5];
        System.out.println(c.getClass());
        ForkJoinDemo[] d = new ForkJoinDemo[100];
        System.out.println(d.getClass());
        System.out.println(c.getClass() == d.getClass());

    }
}

 打印结果:

class [I
class [I
true
class [Lcom.malone.threadCurr.ForkJoinDemo;
class [Lcom.malone.threadCurr.ForkJoinDemo;
true

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值