scala type mismatch

26 views
Skip to first unread message

ChengYi Lin

unread,
May 1, 2015, 1:40:13 AM5/1/15
to jooq...@googlegroups.com
Hi,
I got an exception in the following code:

val result = ctx.select(q.Date, q.Symbol, q.Close,
        isnull(t.FIINetBuyVol, 0)    as FIINetBuyVol).fetch()

type mismatch;
 found   : org.jooq.TableField[prod.tables.records.II3TradeRow,Long]
 required: org.jooq.Field[Any]
Note: Long <: Any (and org.jooq.TableField[prod.tables.records.II3TradeRow,Long] <: org.jooq.Field[Long]), but Java-defined trait Field is invariant in type T.
You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)]


I have to convert 0 to java.lang.Long. Is there a implict way?

val result = ctx.select(q.Date, q.Symbol, q.Close,
        isnull(t.FIINetBuyVol, java.lang.Long.valueOf(0))    as FIINetBuyVol).fetch()

Thanks.

Lukas Eder

unread,
May 6, 2015, 1:44:41 PM5/6/15
to jooq...@googlegroups.com
Hello,

I have just run into this issue recently myself. This seems to be a well-known issue with the Scala compiler when it has to infer generics with Java:

The solution seems to be to explicitly bind the generic type [T] to [java.lang.Long]:

isnull[java.lang.Long](t.FIINetBuyVol, 0)

That's a bit nasty, but unfortunately, I cannot think of a different workaround right now...

Hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages