Reputation: 7468
I am going through a Scala book, and it states few concepts like:
Expression evaluates to a value
A value a an object
Expression has a type
A value doesn't have a type
Value is an object but it doesn't have a type.
How is it possible? In jvm, objects are of certain type, isn't?
Upvotes: 0
Views: 79
Reputation: 170713
The distinction here is that objects have a class, but it's not the same as a type. E.g.
val list = List(1, 2, 3)
The type of list
is List[Int]
; when you run the program, you can see in the debugger (or by calling list.getClass
) that its class is something called $colon$colon
(which corresponds to ::
in Scala code).
val list2 = List.empty[Int]
val list3 = List("")
list2
has the same type as list1
, but a different class; list3
has a different type, but the same class.
Upvotes: 3