@@ -59,7 +59,7 @@ In that syntax:
59
59
Here are two examples of a one-line method named ` add ` that takes two ` Int ` input parameters.
60
60
The first version explicitly shows the method’s ` Int ` return type, and the second does not:
61
61
62
- {% tabs method_2 class=tabs-scala-version %}
62
+ {% tabs method_2 %}
63
63
{% tab 'Scala 2 and 3' for=method_2 %}
64
64
65
65
``` scala
@@ -77,7 +77,7 @@ Declaring the return type can make it easier to understand it when you look at i
77
77
78
78
Invoking a method is straightforward:
79
79
80
- {% tabs method_3 class=tabs-scala-version %}
80
+ {% tabs method_3 %}
81
81
{% tab 'Scala 2 and 3' for=method_3 %}
82
82
83
83
``` scala
@@ -90,7 +90,7 @@ val x = add(1, 2) // 3
90
90
The Scala collections classes have dozens of built-in methods.
91
91
These examples show how to call them:
92
92
93
- {% tabs method_4 class=tabs-scala-version %}
93
+ {% tabs method_4 %}
94
94
{% tab 'Scala 2 and 3' for=method_4 %}
95
95
96
96
``` scala
@@ -146,7 +146,7 @@ In that method:
146
146
147
147
When you paste that code into the REPL, you’ll see that it works as desired:
148
148
149
- {% tabs method_6 class=tabs-scala-version %}
149
+ {% tabs method_6 %}
150
150
{% tab 'Scala 2 and 3' for=method_6 %}
151
151
152
152
``` scala
@@ -162,7 +162,7 @@ Because almost everything in Scala is an _expression_---meaning that each line o
162
162
163
163
This becomes more clear when you condense that method and write it on one line:
164
164
165
- {% tabs method_7 class=tabs-scala-version %}
165
+ {% tabs method_7 %}
166
166
{% tab 'Scala 2 and 3' for=method_7 %}
167
167
168
168
``` scala
@@ -245,7 +245,7 @@ def makeConnection(timeout: Int = 5_000, protocol: String = "http") =
245
245
246
246
Because the parameters have default values, the method can be called in these ways:
247
247
248
- {% tabs method_10 class=tabs-scala-version %}
248
+ {% tabs method_10 %}
249
249
{% tab 'Scala 2 and 3' for=method_10 %}
250
250
251
251
``` scala
@@ -270,7 +270,7 @@ Notice that by using default parameter values, it appears to the consumer that t
270
270
If you prefer, you can also use the names of the method parameters when calling a method.
271
271
For instance, ` makeConnection ` can also be called in these ways:
272
272
273
- {% tabs method_11 class=tabs-scala-version %}
273
+ {% tabs method_11 %}
274
274
{% tab 'Scala 2 and 3' for=method_11 %}
275
275
276
276
``` scala
@@ -286,7 +286,7 @@ makeConnection(protocol="https", timeout=10_000)
286
286
In some frameworks named parameters are heavily used.
287
287
They’re also very useful when multiple method parameters have the same type:
288
288
289
- {% tabs method_12 class=tabs-scala-version %}
289
+ {% tabs method_12 %}
290
290
{% tab 'Scala 2 and 3' for=method_12 %}
291
291
292
292
``` scala
@@ -298,7 +298,7 @@ engage(true, true, true, false)
298
298
299
299
Without help from an IDE that code can be hard to read, but this code is much more clear and obvious:
300
300
301
- {% tabs method_13 class=tabs-scala-version %}
301
+ {% tabs method_13 %}
302
302
{% tab 'Scala 2 and 3' for=method_13 %}
303
303
304
304
``` scala
@@ -324,7 +324,7 @@ When you create arity-0 methods:
324
324
325
325
For example, this method performs a side effect, so it’s declared with empty parentheses:
326
326
327
- {% tabs method_14 class=tabs-scala-version %}
327
+ {% tabs method_14 %}
328
328
{% tab 'Scala 2 and 3' for=method_14 %}
329
329
330
330
``` scala
@@ -336,7 +336,7 @@ def speak() = println("hi")
336
336
337
337
Doing this requires callers of the method to use open parentheses when calling the method:
338
338
339
- {% tabs method_15 class=tabs-scala-version %}
339
+ {% tabs method_15 %}
340
340
{% tab 'Scala 2 and 3' for=method_15 %}
341
341
342
342
``` scala
@@ -387,7 +387,7 @@ def isTruthy(a: Any) =
387
387
388
388
These examples show how that method works:
389
389
390
- {% tabs method_17 class=tabs-scala-version %}
390
+ {% tabs method_17 %}
391
391
{% tab 'Scala 2 and 3' for=method_17 %}
392
392
393
393
``` scala
@@ -624,7 +624,7 @@ Their main purpose is to let you add new functionality to closed classes.
624
624
As shown in that section, imagine that you have a ` Circle ` class, but you can’t change its source code.
625
625
For instance, it may be defined like this in a third-party library:
626
626
627
- {% tabs method_23 class=tabs-scala-version %}
627
+ {% tabs method_23 %}
628
628
{% tab 'Scala 2 and 3' for=method_23 %}
629
629
630
630
``` scala
@@ -636,7 +636,7 @@ case class Circle(x: Double, y: Double, radius: Double)
636
636
637
637
When you want to add methods to this class, you can define them as extension methods, like this:
638
638
639
- {% tabs method_24 class=tabs-scala-version %}
639
+ {% tabs method_24 %}
640
640
{% tab 'Scala 3 only' for=method_24 %}
641
641
642
642
``` scala
@@ -651,7 +651,7 @@ extension (c: Circle)
651
651
652
652
Now when you have a ` Circle ` instance named ` aCircle ` , you can call those methods like this:
653
653
654
- {% tabs method_25 class=tabs-scala-version %}
654
+ {% tabs method_25 %}
655
655
{% tab 'Scala 2 and 3' for=method_25 %}
656
656
657
657
``` scala
0 commit comments