我试图创建一个Java对象数组,并将该数组放置在其第二个索引处(为了用该数组表示自相似分形),但当我尝试访问theArray[1][1][0]
时,出现以下错误:
Main.java: 11: error: array required, but Object found
。
这是我到目前为止尝试过的,但不确定为什么它不起作用:
import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Object[] theArray = new Object[2];
theArray[0] = "This array should contain itself at its second index.";
theArray[1] = theArray; //Now I'm attempting to put the array into itself.
System.out.println(theArray[1][1][0]) //Main.java:11: error: array required, but Object found
}
}
我是否可以将Java数组放在其自身内部,就像我在这里尝试的那样?
((Object[])((Object[])theArray[1])[1])[0]
:) - Eng.FouadObject[]
实例,导致需要进行大量的类型转换;这确实乍一看有点晦涩。 - FThompson