Sighs
Sighs

Reputation: 25

Is val a type of variable in Scala?

I understand the difference between val and var in Scala. My question is would val be considered a type of variable, immutable type, in Scala still? Some online resources do consider val as different type of variable while others do not.

Upvotes: 0

Views: 378

Answers (1)

Dmytro Mitin
Dmytro Mitin

Reputation: 51723

Types are Int, String, Boolean, List[Double], ...

https://scala-lang.org/files/archive/spec/2.13/03-types.html

Value x in val x: Int and variable x in var x: Int are different "sorts" of identifiers with the same type Int.

https://scala-lang.org/files/archive/spec/2.13/04-basic-declarations-and-definitions.html#value-declarations-and-definitions

Upvotes: 4

Related Questions