@@ -82,8 +82,8 @@ import logging.Logger.info
82
82
class Project (name : String , daysToComplete : Int )
83
83
84
84
class Test :
85
- val project1 = new Project (" TPS Reports" , 1 )
86
- val project2 = new Project (" Website redesign" , 5 )
85
+ val project1 = Project (" TPS Reports" , 1 )
86
+ val project2 = Project (" Website redesign" , 5 )
87
87
info(" Created projects" ) // Prints "INFO: Created projects"
88
88
```
89
89
{% endtab %}
@@ -104,7 +104,7 @@ An object with the same name as a class is called a _companion object_. Converse
104
104
105
105
{% tab 'Scala 2' for=companion-object-circle %}
106
106
``` scala
107
- import scala .math ._
107
+ import scala .math .pow
108
108
109
109
case class Circle (radius : Double ) {
110
110
import Circle ._
@@ -123,10 +123,10 @@ circle1.area
123
123
124
124
{% tab 'Scala 3' for=companion-object-circle %}
125
125
``` scala
126
- import scala .math ._
126
+ import scala .math .pow
127
127
128
128
case class Circle (radius : Double ):
129
- import Circle ._
129
+ import Circle .*
130
130
def area : Double = calculateArea(radius)
131
131
132
132
object Circle :
@@ -172,13 +172,13 @@ scalaCenterEmail match {
172
172
{% endtab %}
173
173
174
174
{% tab 'Scala 3' for=companion-object-email %}
175
- ``` scala mdoc
175
+ ``` scala
176
176
class Email (val username : String , val domainName : String )
177
177
178
178
object Email :
179
179
def fromString (emailString : String ): Option [Email ] =
180
180
emailString.split('@' ) match
181
- case Array (a, b) => Some (new Email (a, b))
181
+ case Array (a, b) => Some (Email (a, b))
182
182
case _ => None
183
183
184
184
val scalaCenterEmail = Email .fromString(" scala.center@epfl.ch" )
0 commit comments