scala> def check(a: Int, b: Int): (Int, Int) = {
(3, 4)
}
The returning type is (Int, Int)
. How is this possible? What is S
As @dhg mentioned, (Int, Int)
is equals to Tuple2[Int, Int]
In second sample you use pattern matching in variable definition. You can use it with tuples, case classes and with everything which has extractors. Actually, everything works via extractors.
scala> val p = Point(1, 2)
p: Point = Point(1,2)
scala> val Point(x, y) = p
x: Int = 1
y: Int = 2
scala> val Property = "(.+)=(.+)".r
Property: scala.util.matching.Regex = (.+)=(.+)
scala> val Property(name, value) = "name1=value1"
name: String = name1
value: String = value1
The type (Int, Int)
is just a nicer way of writing Tuple2[Int,Int]