toadzky
04/03/2024, 9:03 PMvalue class
not working as expected. it seems like i'm doing stuff the way the docs say should work, but it's not actually working. (details in thread)toadzky
04/03/2024, 9:04 PMtoadzky
04/03/2024, 9:04 PMtoadzky
04/03/2024, 9:05 PMUnresolved reference. None of the following candidates is applicable because of receiver type mismatch
toadzky
04/03/2024, 9:05 PMChris Fillmore
04/03/2024, 9:11 PMtoadzky
04/03/2024, 9:14 PMtoadzky
04/03/2024, 9:16 PMChris Fillmore
04/03/2024, 9:29 PMtoadzky
04/03/2024, 9:33 PMsindrenm
04/03/2024, 9:33 PMtoadzky
04/03/2024, 9:35 PMinline
aspect kind of makes it feel like it should just auto-become whatever it's wrapping under the hood, but i get why it doesn't - both from technical and philosophical perspectivesagrosner
04/04/2024, 12:13 AMRuckus
04/04/2024, 3:03 AMtypealias
?sindrenm
04/04/2024, 7:26 AMtypealias
will essentially be that, but that would remove the type safety aspect from it:
typealias UserId = String
typealias ItemId = String
fun getUser(id: UserId) {}
fun getItem(id: ItemId) {}
fun main() {
val itemId: ItemId = "foo"
getUser(itemId) // this would still compile
}
@JvmInline value class UserId(val value: String)
@JvmInline value class ItemId(val value: String)
fun getUser(id: UserId) {}
fun getItem(id: ItemId) {}
fun main() {
val itemId: ItemId = "foo"
getUser(itemId) // this would not compile
}
toadzky
04/04/2024, 1:56 PMRuckus
04/04/2024, 3:25 PMtype alias doesn't do the type enforcement
But, isn't that exactly what you're asking for? How do you expect both "I want the new type to be treated like the wrapped type" and "I want the type enforcement for the new type"?
toadzky
04/04/2024, 3:33 PMtoadzky
04/04/2024, 3:34 PMRuckus
04/04/2024, 3:41 PMRuckus
04/04/2024, 3:42 PMtoadzky
04/04/2024, 3:43 PMtoadzky
04/04/2024, 3:44 PMRuckus
04/04/2024, 3:46 PM.substring
on a value class Regex(val pattern: String)
, or red / green
on value class Color(val data: Int)
, so it still feels like a pretty arbitrary "when I want it to" to me, if that makes sense.Ruckus
04/04/2024, 3:47 PMclass MyInterfaceWrapper(
val myInterface: MyInterface
) : MyInterface by myInterface
That's still perfectly valid, no value class needed.toadzky
04/04/2024, 3:54 PMtoadzky
04/04/2024, 3:55 PMRuckus
04/04/2024, 3:55 PMRuckus
04/04/2024, 3:59 PM