Is it possible in Java to override 'toString' for an Objects array?

前端 未结 7 592
一整个雨季
一整个雨季 2020-11-28 12:00

Is it possible in Java to override a toString for an Objects array?

For example, let\'s say I created a simple class, User (it doesn\'t really matter wh

7条回答
  •  借酒劲吻你
    2020-11-28 12:54

    The only way you can do this is to re-compile Object.toString() and add instanceof clauses.

    I had requested a change in Project Coin to handle arrays in a more object orientated way. I felt that it's too much for beginners to learn all the functionality you need in Array, Arrays and 7 other helper classes which are commonly used.

    I think in the end it was concluded that to make arrays properly object orientated is a non-trivial task which will be pushed back to Java 9 or beyond.

提交回复
热议问题