I cannot figure out why calling getBytes() twice on a String returns two byte arrays that are not equal():
final String aString = "hello world";
System.out.println(aString.getBytes());
System.out.println(aString.getBytes());
System.out.println(aString.getBytes());
Prints:
[B@59887d29
[B@fd13cab
[B@71e606a9
E.g. the following assertion always fails:
Assert.assertEquals(aString.getBytes(), aString.getBytes());
From the doc, I wasn't expecting any nondeterminism! What am I missing?
When converting back to String, the result is the expected one, so my best guess is some uninitialized padding bit?
I.e. the following assertion always passes:
Assert.assertEquals(new String(aString.getBytes()), new String(aString.getBytes()));