Conversation

I wrote a little Java today. And for a C++ dev, of the more modern variety, those new’s were painful: Timer timer C++ brain: Ah that’s good. Timer timer = new Timer(); C++ brain: Oh no, baby, what did you do???
Whatever Judgingyou GIF
GIF
11
70
They forgot to provide a proper equals implementation for arrays early so, so for arrays, they ended up being locked into the equals method checking object identity. So, for most stuff including strings, you use equals to check equality, but arrays need java.util.Arrays.equals.
1
1
The next problem is that java.util.Arrays.equals will call the equals method for each element in the array so of course that doesn't work properly for nested arrays due to the messed up equals implementation. So, you need java.util.Arrays.deepEquals to deal with that. Sigh.
2
2
Show replies