I currently have a Tile
class that extends a Node
class, and want to downcast an array of Nodes to an array of Tiles like so:
class Node<T> {
Node[] neighbours;
private final T value;
}
class Tile extends Node {
public Tile(Point value) {
super(value);
}
Tile[] neighbours = (Tile[]) this.getNeighbours;
}
At the moment the compiler is throwing A ClassCastException and I do not know how to fix it.
I am not 100% familiar with inheritance, but I thought since Tile is a subclass this should be a safe casting from Nodes to Tiles.