Here, I'm trying to initialize an array of Objects in Java, but I can't figure out how to initialize a nested array of objects. I tried creating an array of objects with a string as the first element and an array of strings as the second element.
The error message that I encountered:
Main.java:8: error: illegal initializer for Object
And the code that produced this error was:
import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Object[] multiDimensionalObjectArray = {"Hi!", {5, 5}};
}
}
Object, I don't see why it should be impossible to create an array with a string as its first object and its array as its second object. Is there any way to work around this problem?