Reputation:
I'm currently reading the book atomic kotlin where the definition says Kotlin, A data type provides a set of values from which an expression may take its values and I counter to that saying isn't it the variable of data type which provides the value ? I don't know can anybody please explain ?
A data type provides a set of values from which an expression may take its values
Upvotes: 1
Views: 44
Reputation: 37660
What the sentence is telling you is that a type is a set of values, and when you evaluate an expression of this type, the (single) value of that expression is one value of that set.
isn't it the variable of data type which provides the value ?
A variable of a given data type provides one value when it's read. This is one particular kind of expression of this type. More complex expressions also have a type, and provide one value of that type when evaluated.
The important bit here is that one expression evaluates to one value, while the type is the set of all possible values for expressions of such type.
For example, as mentioned by @Ruthvik, the Int
type is the set of all possible integer values between Int.MIN_VALUE
and Int.MAX_VALUE
.
Upvotes: 1