Hello,

Just copying my answer on Stackoverflow to the user-group:

Unfortunately, Java does not know declaration-site variance like C# or
Scala:

// C# styleinterface Result<out Record> { ... }
// Scala style
trait Result[+Record] { ... }

Both of the above would allow assigning the following

Result<Record4<T1, ...>> r1 = ...Result<Record> r2 = r1;

But Result <http://www.jooq.org/javadoc/latest/org/jooq/Result.html> is
really defined as:

interface Result<R extends Record> {}

Now, since your query expression binds <R> to Record4<T1, ...>, this is
what you're going to get:

Result<Record4<T1, ...>> r1 = selectDistinct(...).fetch();

Alternatively, you can just use a wild-card

Result<? extends Record> r2 = r1;
// Or shorter:Result<?> r3 = r1;

Another option is to force removal of typesafety when expressing your query:

Result<Record> r4 = selectDistinct(new Field[] { ... }).fetch();


Source: http://stackoverflow.com/a/20727581/521799
J.B. Nizet's answer has some more insight into how Java generics work:
http://stackoverflow.com/a/20727510/521799


2013/12/22 bruce buchanan <[email protected]>

> I'm using pretty standard syntax here, I think:
>
> Result<Record> = ...selectDistinct(...).fetch();
>
> but it wont compile because the above returns Result<Record4<...>> which
> is an autogenerated interface, which is a subinterface of Record but the
> compiler remains unhappy
>
> I suppose normally java will treat this as an implicit cast? doesnt seem
> like I should be doing any explicit casting?
>
> thanks
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to