Stefan Oltmann
01/13/2022, 10:52 AM@JvmInline
value class PhotoUri(val value: String)
In Swift PhotoUri
is not defined according to the error message.
Attributes that use it seem to be of type Any
now.
If I change that to an data class it's available.
How can I use value classes with Kotlin v1.6.10?hfhbd
01/13/2022, 10:56 AMStefan Oltmann
01/13/2022, 11:01 AMPaul Woitaschek
01/13/2022, 3:32 PMStefan Oltmann
01/13/2022, 3:32 PMPaul Woitaschek
01/13/2022, 3:32 PMPaul Woitaschek
01/13/2022, 3:33 PMPaul Woitaschek
01/13/2022, 3:33 PMStefan Oltmann
01/13/2022, 3:33 PMStefan Oltmann
01/13/2022, 3:34 PMAny
Paul Woitaschek
01/13/2022, 3:34 PMStefan Oltmann
01/13/2022, 3:35 PMvalue
classes... Phillip pointed me to the inline
(the former construct) classes which are not supported.Paul Woitaschek
01/13/2022, 3:35 PMStefan Oltmann
01/13/2022, 3:36 PMPaul Woitaschek
01/13/2022, 3:36 PMStefan Oltmann
01/13/2022, 3:36 PMPaul Woitaschek
01/13/2022, 3:37 PMStefan Oltmann
01/13/2022, 3:39 PMPhotoSourceId
instead of the int
to be type safety.
data class PhotoSource(
val id: PhotoSourceId,
val type: PhotoSourceType,
)
value class PhotoSourceId(val value: Int)
Stefan Oltmann
01/13/2022, 3:39 PMPaul Woitaschek
01/13/2022, 3:39 PMStefan Oltmann
01/13/2022, 3:40 PMStefan Oltmann
01/13/2022, 3:43 PMPaul Woitaschek
01/13/2022, 3:44 PMStefan Oltmann
01/13/2022, 3:45 PMPaul Woitaschek
01/13/2022, 3:45 PMStefan Oltmann
01/13/2022, 3:45 PMStefan Oltmann
01/13/2022, 3:47 PMhfhbd
01/13/2022, 3:50 PMStefan Oltmann
01/13/2022, 3:54 PMint
... and people started to mix that up by not paying attention.
This both paths lead to hell πStefan Oltmann
01/13/2022, 3:55 PMStefan Oltmann
01/13/2022, 3:56 PMStefan Oltmann
01/13/2022, 3:59 PMint
into an List<Integer>
will autobox and create a new Integer
object (a long as the number is not so small that in can be taken from the constant pool of course) having a PhotoSourceId
which in reality is an int
hides this and may have unexpected results for everyone that did not look up what type of class my PhotoSourceId
actually is.Stefan Oltmann
01/13/2022, 4:00 PMPaul Woitaschek
01/13/2022, 4:38 PMStefan Oltmann
01/13/2022, 4:40 PM