if I have a value class like `value class Download...
# getting-started
a
if I have a value class like
value class DownloadManagerId(val value:Long)
is there a way to “unwrap” this without having to say
downloadManagerId.value
at each use?
s
not unwrap, but of course you could assign it do a different variable, either directly
val downloadManagerIdValue = downloadManagerId.value
or indirectly ``downloadManagerId.value.let { downloadManagerIdValue -> ... }``. But first you might question yourself if maybe you could rename your initial variable down to
id
since writing
id.value
seems way more palpable (you don't have to put the whole classname in each variable). PS: don't forget the @JvmInline annotation (the only way value classes work currently) and rest assured that value will be an unwrapped Long at runtime (in case your unwrapping was meant to be an optimization instead of a name shortening).
👍 1