Jxtps Jxtps - 26 days ago 5x
Scala Question

Is there ever a reason to use Scala's StringLike.replaceAllLiterally over Java's String.replace?

Scala's StringLike has the method

This seems to be very similar in effect to Java's String with the method
String replace(CharSequence target, CharSequence replacement)

Is there ever a reason to use the Scala version?

(Not going through the regex compile step would seem to enable Java's version to be faster, though I haven't benchmarked that)


It's to avoid collision with replace on StringBuilder. StringBuilder is also a StringLike. Why the StringBuilder replace wasn't the one to be changed, I'm not sure.

There's no reason to use it on strings unless you want to handle any StringLike (i.e. both wrapped strings and their builders).