The Warning is :
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
I am getting the warning in this line:
l=(List)getHibernateTemplate().find(query,arr);
Here is the complete code:
public Boolean checkLogin(Utilisateur utilisateur) throws Exception
{
Boolean f=false;
try{
List l=null;
String query ="*from utlisateur where login=log and password=log";
String [] arr=new String[2];
arr[0]= utilisateur.getLogin();
arr[1]= utilisateur.getPassword();
l=(List)getHibernateTemplate().find(query,arr);
if(l!=null){
if(l.size()==1){
f=true;
}
}
}
catch(Exception e){
throw new Exc开发者_如何转开发eption("Error from DAO " + e.getMessage());
}
return f;
}
How can I avoid this warning?
If you are using Spring's HibernateTemplate
, the method supports vararg parameters. You should change your call like this:
l = (List) getHibernateTemplate().find(
query, utilisateur.getLogin(), utilisateur.getPassword());
Reference:
- Java Tutorial: Arbitrary Number of Arguments
- Java Language Guide: Varargs
精彩评论