无法再设置“匿名”记录字段
更新 Java 和 JOOQ 后,以前工作的函数似乎遇到了类型转换错误,特别是 record.set/with 行(或设置列的任何版本)...
public void set_col_value(String col, String val, int options) {
final boolean optional = (options & Optional_Value) != 0;
if (val == null) {
if (optional) {
return;
}
throw new RuntimeException("missing value: " + val);
}
final boolean as_bool = (options & As_Boolean) != 0;
if (as_bool) {
if (val.equals("true")) {
record.set(table.field(col), true);
} else if (val.equals("false")) {
record.with(table.field(col), false);
} else {
throw new RuntimeException("bad boolean value: " + val);
}
} else {
record.with(table.field(col), val);
}
}
我收到此错误:
错误:找不到适合 set(Field
,boolean) 的方法
record.set(table.field(col), true);
方法 Record.set(Field ,T#1) 不适用
(推理变量 T#1 具有不兼容的边界等式约束:CAP#2 下限:布尔值)
方法 Record.set(Field ,U,Converter) 不适用
(无法推断类型变量 T#2,U
(实际和形式参数列表的长度不同))
其中 T#1,T#2,U 是类型变量:
T#1 扩展了方法set(Field ,T#1) 中声明的对象
T#2 扩展了方法set(Field ,U,Converter) 中声明的对象 U 扩展了方法 set(Field ,U,Converter)
其中 CAP#1、CAP#2 是新的类型变量:
CAP#1 通过捕获 ?
扩展对象 CAP#2 从 ? 的捕获中扩展对象
After updating Java and JOOQ a previously working function seems to run into a type casting error, specifically the lines record.set/with(or any version of setting a column) ...
public void set_col_value(String col, String val, int options) {
final boolean optional = (options & Optional_Value) != 0;
if (val == null) {
if (optional) {
return;
}
throw new RuntimeException("missing value: " + val);
}
final boolean as_bool = (options & As_Boolean) != 0;
if (as_bool) {
if (val.equals("true")) {
record.set(table.field(col), true);
} else if (val.equals("false")) {
record.with(table.field(col), false);
} else {
throw new RuntimeException("bad boolean value: " + val);
}
} else {
record.with(table.field(col), val);
}
}
I get this error:
error: no suitable method found for set(Field<CAP#1>,boolean)
record.set(table.field(col), true);
method Record.<T#1>set(Field<T#1>,T#1) is not applicable
(inference variable T#1 has incompatible bounds equality constraints: CAP#2 lower bounds: Boolean)
method Record.<T#2,U>set(Field<T#2>,U,Converter<? extends T#2,? super U>) is not applicable
(cannot infer type-variable(s) T#2,U
(actual and formal argument lists differ in length))
where T#1,T#2,U are type-variables:
T#1 extends Object declared in method <T#1>set(Field<T#1>,T#1)
T#2 extends Object declared in method <T#2,U>set(Field<T#2>,U,Converter<? extends T#2,? super U>)U extends Object declared in method <T#2,U>set(Field<T#2>,U,Converter<? extends T#2,? super U>)
where CAP#1,CAP#2 are fresh type-variables:
CAP#1 extends Object from capture of ?
CAP#2 extends Object from capture of ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了回答为什么事情过去有效而不再有效,我需要更多信息(请参阅评论)。您可能还更改了其他内容,包括删除了一些原始类型转换等。
但它们不应该起作用。看看
Record.set(Field, T)
和字段。字段(字符串)
方法。后者返回带有通配符的Field
。您不能只将Field
和boolean
传递给Record::set
方法,即T
类型必须匹配。以下是该特定调用的可能解决方法:
我不记得不需要这样做的 jOOQ 版本...
In order to answer why things used to work and no longer do, I'll need more info (see comments). You probably changed something else as well, including removed some raw type cast, etc.
But they aren't supposed to work. Look at the
Record.set(Field<T>, T)
andFields.field(String)
methods. The latter returnsField<?>
with a wildcard. You can't just passField<?>
andboolean
to theRecord::set
method, theT
types must match.Here's are possible workarounds for that particular call:
I can't remember a jOOQ version where this wasn't required...