ursus
03/13/2023, 1:42 PMclass NboAdapter(
val idAdapter: ColumnAdapter<NboId, String>
...
}
val nboAdapter = NboAdapter(
idAdapter = IdColumnAdapter(::NboId), <--------------- do away with ::NboId
...
)
class IdColumnAdapter<T : Id>(val factory: (String) -> T) : ColumnAdapter<T, String> {
override fun decode(databaseValue: String): T = factory(databaseValue)
override fun encode(value: T): String = value.value
}
interface Id : Comparable<Id> {
val value: String
override fun compareTo(other: Id): Int = value.compareTo(other.value)
}
data class NboId(override val value: String) : Id
is there a way to infer the ::NboId
constructor? I'm trying maybe with reified but that would require T(value)
constructor which is not possible in kotlin/java without reflection, right?
however this does exist
inline fun <reified T : Enum<T>> EnumColumnAdapter(): EnumColumnAdapter<T> {
return EnumColumnAdapter(enumValues())
}
is that some sort of magic? I thought values
was only definied on the concrete enumasdf asdf
03/13/2023, 3:31 PMursus
03/13/2023, 3:33 PMNboId
but turn it around to somethinglike Id<Nbo>
, but not sure if that would help yetasdf asdf
03/13/2023, 3:55 PMursus
03/13/2023, 4:00 PMvalue classes
, those can have only a single value right? maybe a ctor is accessible there generically?asdf asdf
03/13/2023, 4:07 PMValued<T>
interface that value classes would automatically implement that would allow for generic destructuring of themursus
03/13/2023, 4:07 PM