Not directly, you can make a top-level function ne...
# announcements
k
Not directly, you can make a top-level function next to the class with the same name to fake a constructor though. (or an
operator fun invoke
on the companion but that's even uglier)
j
ok, seems like the other alternative is to do an unsafe cast in the identity transformer.... 🤷
r
That would be very unsafe. What if I do
TableColumn<String, Int>("fred")
👆 1
💥 1
s
You could mitigate that by using a typealias:
Copy code
data class TableColumn<T,U>(val rawColumn: T, val transformer: (U) ->T ) {
    constructor(rawColumn: T) : this(rawColumn, { it as T })
}

typealias TableColumnSame<T> = TableColumn<T, T>

fun main() {
    val tc = TableColumnSame(5)
}
Still quite unsafe, though, if you don’t use the typalias on the call site 🙂