无法再设置“匿名”记录字段

发布于 2025-01-09 04:40:20 字数 1630 浏览 0 评论 0原文

更新 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2025-01-16 04:40:20

为了回答为什么事情过去有效而不再有效,我需要更多信息(请参阅评论)。您可能还更改了其他内容,包括删除了一些原始类型转换等。

但它们不应该起作用。看看 Record.set(Field, T)字段。字段(字符串) 方法。后者返回带有通配符的 Field。您不能只将 Fieldboolean 传递给 Record::set 方法,即 T 类型必须匹配。

以下是该特定调用的可能解决方法:

// Using raw types
record.set((Field) table.field(col), true);

// Using unsafe casts
record.set((Field<Boolean>) table.field(col), true);

我不记得不需要这样做的 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) and Fields.field(String) methods. The latter returns Field<?> with a wildcard. You can't just pass Field<?> and boolean to the Record::set method, the T types must match.

Here's are possible workarounds for that particular call:

// Using raw types
record.set((Field) table.field(col), true);

// Using unsafe casts
record.set((Field<Boolean>) table.field(col), true);

I can't remember a jOOQ version where this wasn't required...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文