官术网_书友最值得收藏!

String Interpolators

We've already used String Interpolators, it's hard to avoid using them when they are available to you. Remember when we used them? Yes! When we were learning to create operators on our own:

println(s"Total Amount for order:: ${amountAfterTax(new Amount(firstOrderAmount))}")

This little s here is a String interpolator. While using these, we precede our String with a character named s, and inside double quotes of the String, we can use any variable with a $ and it'll be replaced by its value:

scala> val myAge = s"I completed my $age."
myAge: String = I completed my 25.

This is an example of how we can use interpolators. The s is not the only interpolator existing in Scala. We have a couple more interpolators. We'll go through them one by one.

  • The s interpolator
  • The f interpolator
  • The raw interpolator
主站蜘蛛池模板: 津市市| 巫山县| 汶上县| 峨眉山市| 莫力| 富蕴县| 皮山县| 西华县| 车致| 林周县| 玛曲县| 平南县| 双桥区| 横峰县| 元江| 益阳市| 桂林市| 通化县| 泰宁县| 依安县| 安多县| 宁波市| 白玉县| 海口市| 沂南县| 凌海市| 边坝县| 肥东县| 崇文区| 连州市| 含山县| 大冶市| 哈密市| 盖州市| 邵阳县| 德化县| 喜德县| 大港区| 山丹县| 昆明市| 文化|