1

在编译我的 ActiveAndroid ORM 数据库中的表类时,我收到此错误:

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

这是this所指的方法:

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();
}

我想从我的 ActiveAndroid ORM 数据库表中返回所有 ChildMedicine 对象,其中 Child 列等于传入子参数的 Long Id, Medicine 列等于传入医学参数的 Long Id。

建议我使用显式数组创建来包装 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 数组?

我有一点疑惑!

任何帮助深表感谢...

谢谢,山姆

4

1 回答 1

1

如果不知道该方法的签名,我无法确定where,但您似乎需要的是:

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

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

另一个应该有效的选择:

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

建议我使用显式数组创建来包装 wrap vararg 参数

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

于 2015-03-01T19:53:24.573 回答