原创转载请注明出处:http://agilestyle.iteye.com/blog/2333300
利用字符创插值,你创建的字符串就可以包含格式化的值。
在字符串的前面放置一个s,在你想让Scala插值的标识符之前放置一个$
package org.fool.scala.strings case class Sky(color: String) object StringInterpolation extends App { def print(s: String, n: Int, d: Double): String = s"first: $s, second: $n, third: $d" println(print("Hello", 3, 0.14)) def f(n: Int): Int = n * 2 println(s"f(2) is ${f(2)}") println(s"${Sky("blue")}") }
Console Output