File tree Expand file tree Collapse file tree 3 files changed +25
-10
lines changed
src/script/scala/progscala3 Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 1
1
// src/script/scala/progscala3/BracesSyntax.scala
2
+
3
+ // For completeness, Scala 2 imports, not allowed in Scala 3:
4
+ import scala .concurrent ._
5
+ import java .util .{Queue => JQueue }
6
+ import java .util .{HashMap => JHashMap , HashSet => _ }
7
+
2
8
// Braces syntax - valid in both Scala 2 and 3
3
9
10
+ // Package definition
11
+ // package mypkg { // Can't declare a package in a script!
12
+ // // stuff under mypkg...
13
+ // }
14
+
4
15
// For comprehension
5
16
val evens = for {
6
17
i <- 0 until 10
@@ -58,11 +69,6 @@ def multiline(s: String): String = {
58
69
result
59
70
}
60
71
61
- // Package definition
62
- package mypkg {
63
- // ...
64
- }
65
-
66
72
// Trait, class, and object definition
67
73
trait Monoid [A ] {
68
74
def add (a1 : A , a2 : A ): A
Original file line number Diff line number Diff line change 1
1
// src/script/scala/progscala3/IndentationSyntax.scala
2
+
3
+ // For completeness, Scala 3 imports:
4
+ import scala .concurrent .{given , * }
5
+ import java .util .Queue as JQueue
6
+ import java .util .{HashMap as JHashMap , HashSet as _ }
7
+
2
8
// Significant indentation syntax
3
9
10
+ // Package definition
11
+ // package mypkg: // Can't declare a package in a script!
12
+ // stuff under mypkg...
13
+
4
14
// For comprehension
5
15
val evens = for
6
16
i <- 0 until 10
@@ -53,10 +63,6 @@ def multiline(s: String): String =
53
63
println(s " output: $result" )
54
64
result
55
65
56
- // Package definition
57
- package mypkg:
58
- // ...
59
-
60
66
// Trait, class, and object definition
61
67
trait Monoid [A ]:
62
68
def add (a1 : A , a2 : A ): A
Original file line number Diff line number Diff line change 1
1
// src/script/scala/progscala3/meta/inline/Transparent.scala
2
2
3
3
open class C1
4
- class C2 extends C1
4
+ class C2 extends C1 :
5
+ def hello = " hello from C2"
5
6
6
7
transparent inline def make (b : Boolean ): C1 = if b then C1 () else C2 ()
7
8
8
9
val c1 : C1 = make(true ) // <1>
10
+ // c1.hello // C1.hello doesn't exist!
9
11
val c2 : C2 = make(false ) // <2>
12
+ c2.hello // Allowed!
You can’t perform that action at this time.
0 commit comments