https://kotlinlang.org logo
g

Gustav Elmgren

06/02/2022, 9:36 AM
Is it possible to transform
Column<EntityId<T>>
to
ExpressionWithColumnType<T>
in some way?
For example, using
Copy code
Entity.id.castTo(LongColumnType()
Would that be stupid?
The main reason is that I have a method that accepts
ExpressionWithColumnType<T>
, and it wont accept the id, but any other parameter. And it works if I use
castTo
. But it seems a bit overkill to actually cast (in the generated SQL) it just so the typing works.
e

Emil Kantis

06/02/2022, 10:53 AM
can you change the method?
g

Gustav Elmgren

06/02/2022, 10:54 AM
Yeah, I should be able to do that.
e

Emil Kantis

06/02/2022, 10:55 AM
fun <T> method(expr: ExpressionWithColumnType<T>)
->
fun <T, S : ExpressionWithColumnType<T>> method(expr: S)
should do the trick, no?
since
Column<T>
extends
ExpressionWithColumnType<T>
g

Gustav Elmgren

06/02/2022, 10:58 AM
I think I tried that, but I might have done it completely wrong.
Copy code
Type mismatch.
Required:
ExpressionWithColumnType<Long>
Found:
Column<EntityID<Long>>
Nvm, it must be my implementation that does something strange. It accepted it when I tried your snippet.
Oh. The problem is probably because I have
<T : Comparable<T>, K : ExpressionWithColumnType<in T>>
, and
T
is a simple Long. I guess I could transform it by using
EntityId()
Yeah, it all works when I created the related
EntityId
. Thanks!
7 Views