Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Table<R> and <TableLike> in jOOQ

Tags:

java

sql

jooq

Can someone in a nutshell tell me the difference between these two objects and why one might be used over the other?

like image 712
John Wilson Avatar asked Dec 13 '25 21:12

John Wilson


1 Answers

Nutshell, TL;DR version:

You should only ever reference Table. jOOQ's internals also use TableLike

Full explanation:

jOOQ's DSL is full of little marker interfaces that are there only because the Java language lacks support for union types. For instance, in SQL syntax, a Table<?> (as in CREATE TABLE x ...) and a Select<?> (as in SELECT * FROM ...) are the same thing, when you put that thing in the FROM clause.

In an "ideal" Java language, the FROM clause would be declared as such:

interface SelectFromStep {
    SelectWhereStep from(Table | Select tableReference);
}

Because that's not possible, and because overloading and generic type erasure is a great source of pain when (ab)using generics like jOOQ does, jOOQ has these marker interfaces. Like TableLike, which is the super type of both Table and Select.

It is thus important only as a method parameter type in the jOOQ DSL, not to you as a user.

like image 64
Lukas Eder Avatar answered Dec 15 '25 11:12

Lukas Eder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!