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

3062

被折叠的 条评论
为什么被折叠?



