Why this method gives me an error?
The method:
public Mainsubjects getChosenMain(String loc, int id) {
List list = hibernateTemplate.find("from Mainsubjects where locale = ? and id = ?", loc, id);
Mainsubjects main = (Mainsubjects) list.get(0开发者_JAVA百科);
return main;
}
gives me:
getChosenMain(java.lang.String,int) in fi.utu.tuha.db.DatabaseOperations cannot implement getChosenMain(java.lang.String,int) in fi.utu.tuha.db.DatabaseManager
return type fi.utu.tuha.domain.Mainsubjects is not compatible with java.util.List<fi.utu.tuha.domain.Mainsubjects>
I wonder why. I'm casting the object to return it.
It looks like DatabaseOperations
implements the interface, or extends the class DatabaseManager
. This interface or base class has the method:
public List<Mainsubjects> getChosenMain(String,int)
You have overriden the method with:
public Mainsubjects getChosenMain(String loc, int id)
The cause of the error is that the return types do not match.
精彩评论