I think this is a basic question, but why can I as...
# getting-started
s
I think this is a basic question, but why can I assign properties to data created with`val`?
Copy code
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(platform.appUrl)
s
If I understand your question correctly, it's because
val
doesn't make the variable immutable, it only prevents you from reassigning the variable itself
4
e
intent
is a read-only reference to the particular instance of
Intent
class that you create here.
Intent
is a mutable class. So you can change the properties of this instance of
Intent
class, but you cannot reassign the
intent
value to reference a different instance.
9
s
Fabulous explanations thank you 😁
🙂 1
s
@scottiedog45 If you want fully immutable datatypes, use
data
classes