我有以下课程:
public abstract class AbstractMongoDAO<T extends AbstractChiliEntity> implements IDAO<ObjectId, T> {
// Method 1
protected List<DBObject> getByQuery(Object... pairs) {
DBObject dbobject = //...
return getByQuery(dbobject);
}
// Method 2
protected List<DBObject> getByQuery(Map<String, Object> map) {
DBObject dbobject = //...
return getByQuery(dbobject);
}
// Method 3
protected List<DBObject> getByQuery(DBObject query) {
List<DBObject> dbobjects = //...
return dbobjects;
}
// Inherited methods here - they have nothing at all to do with the methods above.
}
方法 1 和 2 只是构造 DBObject 的不同方法,然后将其传递给方法 3 以查询 MongoDB 实例并返回一组结果。
编译器在方法 1 和 2 的返回语句中抱怨:
The method getByQuery(Object[]) is ambiguous for the type AbstractMongoDAO<T>
为什么是这样?如果我注释掉方法 2,程序就会编译。但是,如果我注释掉方法 1,我会得到相同的编译器错误,但是是针对方法 2。