RFR: 8197594 - String and character repeat

Brian Goetz brian.goetz at oracle.com
Sat Feb 17 17:53:32 UTC 2018


> On Feb 17, 2018, at 9:40 AM, Martin Buchholz <martinrb at google.com> wrote:
> 
> Let me join the chorus of agreement with Brian here.
> 
> The most popular use case will forever be ASCII line of non-letter symbols.

We may also wish to have a repeating version on StringBuilder, though:

    sb.append(INDENT_CHARS, indentLevel)

(or a default method on Appendable with the same effect.)  

By way of background … my primary motivation for these sorts of methods is to take things that require execution as _statements_ (loops, if-then, etc) and turn them into _expressions_, not primarily because they are more compact, but because they are then _composible_.  Repeating a string today requires a loop (yes, I know you can do it with a stream expression), which means it can’t be done inline as a method parameter, requiring you to potentially unroll a deeply nested expression just to create a statement context to do this bit of paperwork.  




More information about the core-libs-dev mailing list