Here is a form of your code that compiles (without description for JsonSerializable ) (in Scala 2.8) along with a more concise wording (which also ends up without dots):
object Javier01 { def javFunc(list: List[Any]): String = { val strItems = new StringBuilder() list.foreach { item => strItems.append ( item match { // case x: JsonSerializable => x.toJson() case y: String => "\"" + y + "\"" case _ => item.toString } ) if (item != list.last) strItems.append(",") } strItems.toString } def rrsFunc(anys: List[Any]): String = anys map { // case x: JsonSerializable => x.toJson() case s: String => "\"" + s + "\"" case x => x.toString } mkString "," def main(args: Array[String]): Unit = { val stuff = List(true, 1, 123.456, "boo!") printf(" stuff : %s%njavFunc(stuff): %s%nrrsFunc(stuff): %s%n%n", stuff, javFunc(stuff), rrsFunc(stuff)) } }
Exiting this run:
% scala Javier01 stuff : List(true, 1, 123.456, boo!) javFunc(stuff): true,1,123.456,"boo!" rrsFunc(stuff): true,1,123.456,"boo!"
source share