英文:
jOOQ with java 15: both interface org.jooq.Record in org.jooq and class java.lang.Record in java.lang match
问题
我刚刚尝试将我的项目升级到Java 15,现在出现以下错误:
接口org.jooq中的org.jooq.Record与java.lang中的类java.lang.Record匹配。
是否有人有解决这个问题的经验?
英文:
I've just tried upgrading my project to Java 15, and now I get the following error:
both interface org.jooq.Record in org.jooq and class java.lang.Record in java.lang match
Does anybody have some experience resolving this issue?
答案1
得分: 10
除了Aniket已经说过的内容之外:
对于Record
类型,导入-on-demand不再起作用
建议的做法是在导入-on-demand语句中添加显式导入:
import org.jooq.*;
import org.jooq.Record;
或者完全停止使用导入-on-demand。例如,在Eclipse中,您可以使用“整理导入”功能将所有导入-on-demand语句扩展为显式导入,具体取决于您实际使用的类型。
使用类型推断
如果在局部变量中出现这个问题,另一种防止这个问题的方法是使用var
:
var record = ctx.fetchOne(TABLE, TABLE.ID.eq(1));
现在您不需要导入该类型。当然,这对于成员类型、方法参数和返回类型是不起作用的。
我们将尝试更好地记录这个问题:https://github.com/jOOQ/jOOQ/issues/10646
英文:
In addition to what Aniket already said:
Import-on-demand no longer works for Record
The recommendation is to add an explicit import to your import-on-demand statement:
import org.jooq.*;
import org.jooq.Record;
Or to stop using import-on-demand entirely. E.g. in Eclipse, you can use the "Organize Imports" feature to expand all your import-on-demand statements to explicit imports, depending on the types you're actually using.
Using type inference
Another way to prevent this problem if it happens with local variables is to use var
:
var record = ctx.fetchOne(TABLE, TABLE.ID.eq(1));
Now you don't have to import the type. This doesn't work with member types, method parameter and return types, of course.
We'll try to better document this: https://github.com/jOOQ/jOOQ/issues/10646
答案2
得分: 5
Java 14引入了records。java.lang.Record
是record
的超类,由于java.lang
中的每种类型都会被自动导入,它与org.jooq.Record
发生了冲突。有两种解决方案:
- 使用完全限定的名称替代
Record
,并移除导入语句。例如:使用org.jooq.Record
代替Record
。(不要忘记移除import
语句)。 - 将
org.jooq.Record
重新声明为某个特定的名称。(在您的情况下,我认为这是不可能的,因为它是一个第三方库。)
英文:
Java 14 introduced records. java.lang.Record
is a superclass of record
which is conflicting with org.jooq.Record
since every type in java.lang
is auto imported. There are two solutions:
- Use a fully qualified name instead of
Record
and remove the import. Eg:org.jooq.Record
instead ofRecord
. (Don't forget to remove theimport
statement). - Redeclare the
org.jooq.Record
to something specific. (Which I believe is not possible in your case as it's a third-party library.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论