🔴 Scala
Beginner
What is Scala's type system and what is type inference?
Answer
Scala has a powerful static type system that catches errors at compile time. Every expression has a type. Type inference: Scala's compiler infers types from context, so you usually don't need explicit annotations. val x = 42 — the compiler infers x: Int. val names = List("Alice", "Bob") — inferred as List[String]. Type hierarchy: Any is the root. AnyVal (Int, Double, Boolean, etc.) and AnyRef (all reference types). Nothing is the bottom type (subtype of all types) used for expressions that never return (throw, infinite loop). Null is a subtype of all reference types. Generics: class Box[T](value: T). Variance: covariant (+T), contravariant (-T), invariant. Scala's type system enables powerful abstractions while maintaining type safety.