关于包装我的可变参数参数的困惑

Confusion regarding wrapping my varargs argument

在我的 ActiveAndroid ORM 数据库中编译我的 class 这是一个 table 时,我得到这个错误:

警告:(33, 50) 可变参数方法的非可变参数调用,最后一个参数的参数类型不准确; 转换为对象以进行可变参数调用 转换为 Object[] 以进行非可变参数调用并抑制此警告

这是指的方法:

public static ChildMedicine getChildMedicine(Child child, Medicine medicine)
{
return new Select()
        .from(ChildMedicine.class)
        .where("Child = ? AND Medicine = ?", new Long[]{child.getId(), medicine.getId()})
        .executeSingle();
}

我想 return 我的 ActiveAndroid ORM 数据库中的所有 ChildMedicine 对象 table 其中 Child 列等于传入子参数的 Long Id,而 Medicine 列等于通过医学参数。

我被建议用这样的显式数组创建来包装 wrap vararg 参数:

public static ChildMedicine getChildMedicine(Child child, Medicine medicine)
{
return new Select()
        .from(ChildMedicine.class)
        .where("Child = ? AND Medicine = ?", new Object[]{new Long[]{child.getId(), medicine.getId()}})
        .executeSingle();
}

但是,这会不会导致我的 Select() 方法无法正常工作,因为我现在在方法的 where 部分中有一个包含两个 Long 数组的数组,而不是包含两个 Long 的 Long 数组?

有点懵!

非常感谢任何帮助...

谢谢, 山姆

不知道 where 方法的签名我不能确定,但​​看来你需要的是:

return new Select()
        .from(ChildMedicine.class)
        .where("Child = ? AND Medicine = ?", new Object[]{child.getId(), medicine.getId()})
        .executeSingle();

这是假设 where 的签名是 where (String str, Object... params)

另一个应该有效的选项:

return new Select()
        .from(ChildMedicine.class)
        .where("Child = ? AND Medicine = ?", child.getId(), medicine.getId())
        .executeSingle();

I am suggested to wrap the wrap vararg arguments with explicit array creation

不,这不是您的建议。建议您将 ObjectObject[] 传递给 where,具体取决于您希望 Long[] 被视为单个参数还是多个参数。传递包含单个 Long[] 元素的 Object[] 没有任何意义。