You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/Classes.scala
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,8 @@ object Classes extends FlatSpec with Matchers with org.scalaexercises.definition
31
31
*
32
32
* The program defines an executable application `Classes` in form of a top-level singleton object with a `main` method. The `main` method creates a new `Point` and stores it in value `pt`.
33
33
*
34
+
* This also demonstrates the use of a value parameters in ClassWithValParameter(val name: String), which automatically creates an internal property (val name: String) in the class.
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/TypeVariance.scala
+18-17Lines changed: 18 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -99,25 +99,26 @@ object TypeVariance extends FlatSpec with Matchers with org.scalaexercises.defin
99
99
}
100
100
101
101
/** Declaring - indicates contravariance variance. Using - you can apply any container with a certain type to a container with a superclass of that type. This is reverse to covariant. In our example, we can set a citrus basket to an orange or tangelo basket. Since an orange or tangelo basket are a citrus basket. Contravariance is the opposite of covariance:
//val fruitBasket: MyContainer[Fruit] = new MyContainer[Citrus](new Orange) //Bad!
119
+
//val wrongCitrusBasket: MyContainer[Citrus] = new MyContainer[Orange](new Orange) //Bad!
120
+
}
121
+
121
122
/** Declaring neither `-`/`+`, indicates invariance variance. You cannot use a superclass variable reference (\"contravariant\" position) or a subclass variable reference (\"covariant\" position) of that type. In our example, this means that if you create a citrus basket you can only reference that citrus basket with a citrus variable only.
122
123
*
123
124
* Invariance means you need to specify the type exactly:
0 commit comments