Type Inference

val businessName = "Montreux Jazz Café"
def squareOf(x: Int) = x * x
Def fac(n: Int) = if (n == 0) 1 else n * fac(n - 1)
case class MyPair[A, B](x: A, y: B)
val p = MyPair(1, "scala") // type: MyPair[Int, String]

def id[T](x: T) = x
val q = id(1)              // type: Int

The Scala compiler can often infer the type of an expression so you don’t have to declare it explicitly.

Type Inference — Structure map

Clickable & Draggable!

Type Inference — Related pages: