-
-
Notifications
You must be signed in to change notification settings - Fork 4
constant
pannous edited this page Dec 25, 2023
·
2 revisions
As with mutability, there are two kinds of constance:
- 'reference constant': constant variables point to the same objects during their lifetime.
- 'value constant': constant objects don't change (their inner value) during their lifetime.
To simplify the situation, Angle offers the final
keyword which means both:
final x = Node()
x = 7 // error can't change variable x
x.y=z // error can't change Node x
In rare cases one may want to combine both concepts though:
mutable x = constant Node()
x = 7 // ok value was constant, not variable
x.y=z // error can't change inner value
constant x = mutable Node()
x = 7 // error
x.y=z // ok can change x