型別推斷和泛型

Scala 編譯器還可以在呼叫多型方法時或在例項化泛型類時推匯出型別引數:

case class InferedPair[A, B](a: A, b: B)

val pairFirstInst = InferedPair("Husband", "Wife")  //type is InferedPair[String, String]
    
// Equivalent, with type explicitly defined
val pairSecondInst: InferedPair[String, String] 
                      = InferedPair[String, String]("Husband", "Wife")  

上述型別推斷形式類似於 Java 7 中引入的 Diamond Operator