开发者

I have got this warning: non-varargs call of varargs method with inexact argument type for last parameter;

开发者 https://www.devze.com 2023-03-30 01:20 出处:网络
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:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消