Is there some kind of datatype that supportes an n-dimensional array? The problem is that when an array is created the number of dimensions a fixed from the beginning in the datatype:
T[] oneDimensional = ...
T[][] twoDimensional = ...
T[][][] threeDimensional = ...
...
T[]???[] nDimensional = ...
I can create this nDimensinal arrays as shown in the following code, but it seems that there is no way to save them in a variable except as an Object. But with an Object I can't work with the array.
@SuppressWarnings("unchecked")
public static <T> ??? createMultidimensionalArray(Class<T> clazz, int dimensions, int dimensionLength) {
int[] dimArr = new int[dimensions];
for (int i = 0; i < dimensions; i++) {
dimArr[i] = dimensionLength;
}
??? targetArray = (???) Array.newInstance(clazz, dimArr);
}
The question is: What datatype could fit the ???
?
Another attempt of me would be to create a class with some kind of linked array where every dimension gets it's own linked instance of that class. This idea is shown here. Still, since this idea would no longer use native arrays I'd like to avoid it.