Values, Types, and Expressions
Type Inference
Let Scala infer simple expression types.
Type Inference
TypeInference.scala
object Main {
def main(args: Array[String]): Unit = {
val count =
val doubled = count * 2
val next: Int = count + 1
val summary = "doubled=" + doubled
println("count=" + count)
println("next=" + next)
println(summary)
}
}
object Main {
def main(args: Array[String]): Unit = {
val count =
val doubled = count * 2
val next: Int = count + 1
val summary = "doubled=" + doubled
println("count=" + count)
println("next=" + next)
println(summary)
}
}
type-inference
Scala can infer many local types from the value on the right side of an assignment.