How can I put a Java array inside itself? -


i'm attempting create java object array , place array inside @ second index (in order represent self-similar fractal array), when try access thearray[1][1][0], error:

main.java:11: error: array required, object found.

this i've tried far, , i'm not sure why it's not working:

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 @ second index.";         thearray[1] = thearray; //now i'm attempting put array itself.         system.out.println(thearray[1][1][0]) //main.java:11: error: array required, object found     } } 

is possible put java array inside itself, i'm attempting here?

thearray[1] of compile-time type object (since comes array of objects).

you need cast object[] use array.


the fundamental problem you're encountering although array contains valid object, isn't valid type.

you can nest array types arbitrarily – object[][][][][][][][][][][][][] valid type.
however, "bottom level" of type can't array.

you're trying create type array of itself.
using generics, possible:

class evil extends arraylist<evil> { } 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -