https://kotlinlang.org logo
Title
u

ursus

03/12/2019, 1:23 AM
override fun decode(databaseValue: Long) = when (databaseValue) {
        1L -> DbMessageType.APPOINTMENT
        2L -> DbMessageType.FILE
        3L -> DbMessageType.LINK
        4L -> DbMessageType.WEB_MEETING
        5L -> DbMessageType.PIN
        else -> DbMessageType.TEXT
    }

    override fun encode(value: DbMessageType) = when (value) {
        DbMessageType.APPOINTMENT -> 1L
        DbMessageType.FILE -> 2L
        DbMessageType.LINK -> 3L
        DbMessageType.WEB_MEETING -> 4L
        DbMessageType.PIN -> 5L
        DbMessageType.TEXT -> 0L
    }
to get unified - safer, without allocating Pair instance (or any other)?
s

sandi

03/12/2019, 1:37 AM
the longs could be constants and
DbMessageType
could be an inline class with the constant as a parameter
u

ursus

03/12/2019, 3:32 AM
yea but that leaks the integer to the rest of the app, and its only a database thing -.-
d

Dico

03/12/2019, 6:30 AM
That doesn't solve the problem both ways
If you seek not to create any instance then no, there is no way
Sadly
I'd probably just use that right there
Creating a jump table at runtime dynamically, I would like that type of feature