What happened to polymorphism for jOOQ-generated classes?

User1291 :

Let's take the query from my other question:

SelectConditionStep<Record1<String>> query = create
        .select(AUTHOR.LASTNAME.as("AuthorName"))
            .from(
                    (
                            BOOK.leftOuterJoin(BOOK_AUTHOR).on(BOOK.ID.eq(BOOK_AUTHOR.BOOKID))
                    ).leftOuterJoin(AUTHOR).on(AUTHOR.ID.eq(BOOK_AUTHOR.AUTHORID))
            )
            .where(BOOK.ID.eq(1))
        ;

//when
Result<Record1<String>> result = query.fetch();

If I try to replace SelectConditionStep<Record1<String>> with SelectConditionStep<Record>, I get

Incompatible types.

Required: SelectConditionStep<org.jooq.Record>

Found: SelectConditionStep<org.jooq.Record1<java.lang.String>>

and yet ...

package org.jooq;

import javax.annotation.Generated;

/**
 * A model type for a records with degree <code>1</code>
 *
 * @see Row1
 * @author Lukas Eder
 */
@Generated("This class was generated using jOOQ-tools")
public interface Record1<T1> extends Record {...}

So ... what gives?

Unless I'm missing something very obvious, shouldn't I be allowed to treat instances of Record1 as if they were Records?

(And yes, I started questioning myself to the point I needed to check I'm not completely mental: https://ideone.com/0O4mOU )

Thilo :

That is just how generics work in Java.

This does not compile either, with the same error message:

ArrayList<Animal> x = new ArrayList<Dog>(); 
ArrayList<List<String>> x = new ArrayList<ArrayList<String>>();

You may want to type your variable something like SelectConditionStep<? extends Record> query. This way, you tell the compiler that any subclass of Record is acceptable (which is not otherwise the case). If you do that, you will also get a Result<? extends Record> back at the end, though, no longer something typesafe in the number and shape of the columns.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=117698&siteId=1