new StringBuilder(char)

Ulf Zibis Ulf.Zibis at CoSoCo.de
Sat Aug 16 23:24:24 UTC 2014


Additionally nice to have:
(initial capacity with initial char(s))
StringBuilder(int,char)
StringBuilder(int,CharSequence)

-Ulf


Am 08.08.2014 um 22:53 schrieb Eddie Aftandilian:
> Hi all,
>
> We recently realized that calling new StringBuilder(char) does not do what
> you would think it does.  Since there is no char constructor defined, the
> char is widened to an int and the StringBuffer is presized to the
> character's encoded value.  Thus code like this prints an empty string
> rather than the expected "a":
> System.out.println(new StringBuilder('a'));
>
> Would it be possible to add a char constructor to StringBuilder to prevent
> this problem? I understand this would change the behavior of any code that
> is currently doing this, but it's hard to imagine anyone doing this
> intentionally.  Of the ~20 instances we found in Google's codebase, all
> were bugs.  What is your policy on making changes like this where (a) it
> will cause a change in behavior, but (b) the currently behavior is clearly
> wrong?
>
> If you're willing to take the change, I'd be happy to send a patch.
>
> Thanks,
> Eddie
>




More information about the core-libs-dev mailing list