Type Inference
Let the compiler figure out types.
What Is Type Inference?
Scala is statically typed, yet you rarely have to write types out. The compiler infers them from the value on the right-hand side.
This gives you the safety of types with the brevity of a dynamic language.
val n = 42 // inferred Int
val label = "hi" // inferred StringInferring From Literals
When you write val x = 5, the compiler sees the Int literal and gives x the type Int.
A decimal literal becomes a Double, and quoted text becomes a String.
object Main extends App {
val count = 5
val ratio = 1.5
println(count + ratio)
}