```val a get() = Random().nextInt(10)``` Is this ...
# getting-started
f
Copy code
val a
get() = Random().nextInt(10)
Is this the only situation a
val
can return a different value each time it is accessed? (obviously the Random function is replaceable)
a
Yes, because
get()
is a syntax sugar for something like:
Copy code
class A {
String getA() { return new Random().nextInt(10); }
}
f
makes sense
t
You also have property delegates, but technically they work the same.
k
Or if an interface contains a
val
implementors can provide whatever getter they want. Still the same, but something to look out for.