-1

Why does Java not support a nice and readable direct print-out for arrays?

I do know that Arrays.toString can be used to get that, and I also know what the hashcode output means (as explained in Why does the toString method in java not seem to work for an array).

But I am asking myself why the developers did not choose to make arrays directly print the readable representation.

Is it technically impossible? Would it impact performance?

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
jxie0755
  • 1,682
  • 1
  • 16
  • 35
  • `Array` is an object – Ryuzaki L Mar 16 '19 at 01:54
  • Possible duplicate of [Why does the toString method in java not seem to work for an array](https://stackoverflow.com/questions/7060016/why-does-the-tostring-method-in-java-not-seem-to-work-for-an-array) – Mark Sholund Mar 16 '19 at 01:59
  • @Deadpool but everything is an object. it is still a sub-class of Object. – jxie0755 Mar 16 '19 at 02:01
  • @Thevenin I read that, it is a different question – jxie0755 Mar 16 '19 at 02:02
  • Only the Java-Devs can tell you why this decision was made. You may ask them. For StackOverflow, however this question is off-topic, as primarily opinion-based. And will likely get closed for that (see [help] and [answer]). – Zabuzard Mar 16 '19 at 02:25

1 Answers1

2

arrays in java are a special case. There is no java source code for an array class and arrays are implemented in the JVM directly.

Given that, arrays don't have any methods themselves and they do not override any of the default Object methods (Yeah they're treated as objects but they're handled with special bytecodes).

As for why the decided to do that it probably has to do with allowing more flexibility with creating arrays of different types and dimensions, maybe processing speed as well.

Nikos Tzianas
  • 633
  • 1
  • 8
  • 21