After googling for a while, I’m aware that there quite a few ways to copy an array to another in Java, namely using System.arraycopy.
However a few of my friends tried to use this:
boolean a[][] = new boolean[90][90];
boolean b[][] = new boolean[90][90];
/* after some computations */
a = b
This produces a rather non deterministic result, does anyone know what this actually does?
It’s not non-deterministic at all.
simply assigns the value of
btoa. The value ofbis a reference to the array – so now both variables contain references to the same array. The old value ofais irrelevant – and if it referred to an array which nothing else referred to, it will now be eligible for garbage collection.Note that this isn’t specific to arrays – it’s the way all reference types work in Java.
Basically, you’re not copying one array into another at all – you’re copying the reference to an array into another variable. That’s all.