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

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
主站蜘蛛池模板: 宜都市| 三明市| 鹤壁市| 揭阳市| 吉安县| 海淀区| 台北县| 大厂| 衡阳市| 武汉市| 庆安县| 武鸣县| 神木县| 潜山县| 新疆| 怀宁县| 汉源县| 大城县| 宝丰县| 洛扎县| 商河县| 屏东县| 行唐县| 保亭| 四平市| 晋州市| 大理市| 全州县| 广德县| 卓资县| 民丰县| 平陆县| 白朗县| 巫山县| 泌阳县| 阳朔县| 灵石县| 湟源县| 廊坊市| 剑阁县| 九江市|