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

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
主站蜘蛛池模板: 土默特左旗| 灵寿县| 肃北| 莱阳市| 淄博市| 磐石市| 西藏| 乳山市| 宁阳县| 古浪县| 谢通门县| 玛多县| 公安县| 巴彦县| 府谷县| 邓州市| 金山区| 共和县| 信阳市| 太原市| 邵武市| 旬阳县| 舞阳县| 任丘市| 汉寿县| 彭山县| 大宁县| 宁阳县| 潍坊市| 宜章县| 仁怀市| 巴林右旗| 南平市| 讷河市| 磐石市| 石家庄市| 娱乐| 辰溪县| 蒙自县| 镇坪县| 遵义县|