I am attempting to grab a random element from a Set of custom Objects (Space) and receiving an error in doing so.

```
Space[][][][] spaces = new Space[dim][dim][dim][dim];
Set<Space> spaceSet = new HashSet<Space>();

for(int i=0; i<dim; i++)
    for(int j=0; j<dim; j++)
        for(int k=0; k<dim; k++)
            for(int l=0; l<dim; l++) {
                spaces[i][j][k][l] = new Space(i,j,k,l);
                spaceSet.add(spaces[i][j][k][l]);
            }
...
Space s = null;
...

s = (Space[])spaceSet.toArray()[rand.nextInt(spaceSet.size())];  //This line throws the error

```

Error:

```
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LSpace;
    at Maze.generatePath(Maze.java:45)
    at Maze4D.main(Maze4D.java:15)

```