Scala Any

val list: List[Any] = List(
  "a string",
  732,  // an integer
  'c',  // a character
  true, // a boolean value
  () => "an anonymous function returning a string"

list.foreach(element => println(element))

Is the supertype of all types, also called the top type. Any has two direct subclasses: AnyVal and AnyRef.


AnyVal represents value types. There are nine predefined value types and they are non-nullable: Double, Float, Long, Int, Short, Byte, Char, Unit, and Boolean. .


AnyRef represents reference types. All non-value types are defined as reference types. Every user-defined type in Scala is a subtype of AnyRef. .

Scala Any — Structure map

Clickable & Draggable!

Scala Any — Related pages: