编译时收到消息
error: Ambiguous getter for Field(element=flagTest, name=flagTest,
type=boolean, affinity=INTEGER, collate=null, columnName=flagTest,
defaultValue=null, parent=null, indexed=false, nonNull=true).
实体代码为
@Entity
public class MyEntity {
@PrimaryKey(autoGenerate = true)
private long id;
boolean flagTest;
public long getId() {
return id;
}
public void setId(long dummyid) {
this.id = dummyid;
}
public boolean getFlagTest() {
return flagTest;
}
public boolean isFlagTest() {
return flagTest;
}
}
最佳答案
这就是说房间不知道使用哪种方法来获取flagTest值。它可以在getFlagTest和isFlagtest之间选择。
如果您想同时使用这两种方法,则可以使用@Ignore
注释告诉房间忽略其中一种方法(与哪一种无关紧要)。
例如
@Entity
public class MyEntity {
@PrimaryKey(autoGenerate = true)
private long id;
boolean flagTest;
public long getId() {
return id;
}
public void setId(long dummyid) {
this.id = dummyid;
}
@Ignore
public boolean getFlagTest() {
return flagTest;
}
public boolean isFlagTest() {
return flagTest;
}
}
通常
is????
用于布尔值,因为该值只能为true或false,因此getFlagTest方法提供了注释。
关于android - 如何解决歧义方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58151461/