File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -247,11 +247,13 @@ println(s"Name: $firstName $mi $lastName") // "Name: John C Doe"
247
247
248
248
Just precede the string with the letter ` s ` , and then put a ` $ ` symbol before your variable names inside the string.
249
249
250
- For expressions more complex than a single identifier , enclose the expression in curly braces:
250
+ To enclose expressions inside a string , enclose them in curly braces:
251
251
252
- ``` scala
252
+ ~~~ scala
253
253
println(s " 2 + 2 = ${2 + 2 }" ) // prints "2 + 2 = 4"
254
- ```
254
+ val x = - 1
255
+ println(s " x.abs = ${x.abs}" ) // prints "x.abs = 1"
256
+ ~~~
255
257
256
258
#### Other interpolators
257
259
@@ -1320,4 +1322,3 @@ Scala has even more features that weren’t covered in this whirlwind tour. See
1320
1322
1321
1323
1322
1324
1323
-
You can’t perform that action at this time.
0 commit comments