Radoslaw Juszczyk
10/13/2022, 6:16 AMval isTooLate: Boolean
get() = System.currentTimeMillis() > someTimestamp
I find it confusing that hovering over it in the IDE gives:
public final val isTooLate: Boolean
which gives an impression that this value is going to be always the same - but it's not.Vitor Hugo Schwaab
10/13/2022, 6:31 AMisTooLate = false
or isTooLate = true
.
Its definition is final, even thought its result may change.Radoslaw Juszczyk
10/13/2022, 6:54 AMRadoslaw Juszczyk
10/13/2022, 6:59 AMval
bit of it:
val is like Final variable and it's known as immutable in kotlin and can be initialized only single time.
They point out that it is immutable but in reality it is just a read only *var*iable - so it seems that ppl wrongly expect it to be immutable
Regarding the example I provided - in that situation, would you use val
with get {}
or would you use a function fun isTooLate(): Boolean
?Radoslaw Juszczyk
10/13/2022, 7:06 AMRobert Williams
10/13/2022, 8:25 AMRobert Williams
10/13/2022, 8:26 AMRobert Williams
10/13/2022, 8:26 AMRobert Williams
10/13/2022, 8:27 AMfun isTooLate(currentTime: Long = System.currentTimeMillis())
Radoslaw Juszczyk
10/13/2022, 10:41 AMRadoslaw Juszczyk
10/13/2022, 10:41 AM