So I'd like to copy a variable in Java without them sharing the same dataset.
The variable is an array called ChunkSection[] tsec
and I'd like to copy it to ChunkSection[] sec
but without the two having any sort of relationship. I've tried .clone() but it didn't work.
ChunkSection[] sec = null;
tsec = fromChunk.i().clone();
for (ChunkSection s : tsec) {
ArrayList<ChunkSection> chs = new ArrayList<>();
chs.add(s);
sec = (ChunkSection[]) chs.toArray(); <-----
}
The code above generates a ClassCastException on the line that arrow points to.