public static void main(String[] args) {
try{
throw new RuntimeException();
}
catch (Exception e){
System.out.println(e.getStackTrace());
System.out.println(e.getStackTrace());
System.out.println(e.getStackTrace());
}
String[] sArray = new String[]{"a","b"};
System.out.println(sArray);
System.out.println(sArray);
System.out.println(sArray);
}
The above program returns the following output:
[Ljava.lang.StackTraceElement;@50040f0c
[Ljava.lang.StackTraceElement;@2dda6444
[Ljava.lang.StackTraceElement;@5e9f23b4
[Ljava.lang.String;@4783da3f
[Ljava.lang.String;@4783da3f
[Ljava.lang.String;@4783da3f
Can someone please explain why does StackTraceElement[]'s hashcode (the last 8 chars of the toString()'s output) return different each time, since the array is not getting changed?
The same is not getting changed for String[].