Sasha O
Sasha O

Reputation: 3749

Why no StringBuilder.+=(String) in Scala?

This behavior seems to be broken (I am using Scala 2.9.1)

var b= new StringBuilder

These are OK:

b+='a'
b.append('b') 
b.append("de")

This produces compile error:

b+="de"

Any idea as to why only StringBuilder#+=(c: Char) exists whereas both StringBuilder#append(c:Char) and StringBuilder#append(s:String) happily co-exist? What is wrong with declaring and implementing StringBuilder#+=(s: String)?

Is it oversight or some deeper problem in the Scala type system?

Upvotes: 10

Views: 10643

Answers (1)

Jean-Philippe Pellet
Jean-Philippe Pellet

Reputation: 59994

Try b ++= "de". A String is considered a collection of Chars.

Upvotes: 25

Related Questions