IO.println behavior on char[]

Ethan McCue ethan at mccue.dev
Sat Jun 28 17:05:17 UTC 2025


Yeah it's easy enough to work around, just noting the divergence

On Sat, Jun 28, 2025, 12:42 PM David Alayachew <davidalayachew at gmail.com>
wrote:

> Ah, I see you were referring to System.out.
>
> Adding that overload makes sense. Though, I would rather it default to
> doing Arrays.toString, as opposed to just the one overload. That way, all
> arrays would be printable.
>
> That was a common pain point for my students. Try to print an array of
> objects, and they only get an array address. And since they don't recognize
> that it's an address, it created some confusing bugs, as they think the
> hexadecimal address string was from previous or following print statements.
>
> On Sat, Jun 28, 2025, 12:36 PM David Alayachew <davidalayachew at gmail.com>
> wrote:
>
>> Is there a char[] overload? I just checked the javadoc for 24 and 25, and
>> I only see Object, String, and no-arg overloads. Not char[].
>>
>> On Sat, Jun 28, 2025, 6:40 AM Ethan McCue <ethan at mccue.dev> wrote:
>>
>>> I was going through some examples in my writing and noticed that
>>>
>>> IO.println(new char[] { 'a', 'b' });
>>>
>>> will hit the Object overload of System.out.println and not the char[]
>>> overload
>>>
>>> This breaks a few of my examples
>>> https://javabook.mccue.dev/arrays/aliasing
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250628/1bb3f3f4/attachment-0001.htm>


More information about the amber-dev mailing list