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

来源:互联网 发布:薪酬数据分析方法统计 编辑:程序博客网 时间:2024/05/22 01:22
Object[]  objs = new Object[3];
Object obj 
= objs;
objs 
= (Object[])obj;

另外,下文对java中的数组的本质做了一些探讨:
http://dev.csdn.net/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
原创粉丝点击