关于java中数组也是对象的强悍解释

本文通过具体实例演示了Java中对象数组的特性和行为,并对比了基本类型数组与对象数组之间的转换过程,揭示了Java内存管理和类型转换的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Object[]  objs = new Object[3];
Object obj 
= objs;
objs 
= (Object[])obj;

另外,下文对java中的数组的本质做了一些探讨:
http://dev.youkuaiyun.com/author/DeepNightTwo/afb7e220bdf5423ba656f84b6a183b44.html

另,
/*
 * TestObjectArray.java, 2007-6-16 17:07:29.
 *
 * CopyRight (c) 2007-2007, yethyeth ,All rights reserved.
 *
 * This file is licenced under the Apache License.
 *
 *
 * this file shows that object arrays is treated as objects.
 
*/

package cn.yethyeth.sample;

public class TestObjectArray {

    
/**
     * 
@param args
     
*/

    
public static void main(String[] args) {
        
// TODO Auto-generated method stub
        Object[] objs = new Object[2];
        objs[
0= new Integer(0);
        objs[
1= new Integer(1);
        Object obj 
= (Object)objs;
        Object[] objs2 
= (Object[])obj;
        System.out.println(objs2[
1]);
        
        
int[] is = new int[2];
        is[
0= 0;
        is[
1= 1;
        
        Object obj1 
= (Object)is;
        System.out.println(obj1);
        System.out.println(obj1.getClass() );
        
int[] iss = (int[])obj1;
        System.out.println( iss[
1]);
    }


}


结果:
1
[I@148cc8c
class [I
1
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值