class 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 enum