2

コードを実行すると、次のエラーが表示されます このメソッドが記述されているクラスでクラス Mycomp のオブジェクトを作成する必要があります

Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments 

(リスト)。推論されたタイプの Product は、境界付きパラメーターの有効な代替ではありません >

    public List<Product> displaySortedShoppingCart(String userName) throws ShoppingCartNotFoundException
{
    getConnection();
    ResultSet rs;
    boolean flag=false;
    List<Product> l=new ArrayList<Product>();
    String sql="select *from scart where username='"+userName+"'";
    try {
        rs=stmt.executeQuery(sql);
        while(rs.next())
        {
            flag=true;
            Product pr=new Product();
            pr.setname(rs.getString(2));
            l.add(pr);
            //System.out.println(rs.getString(2));
        }
        if(flag==false)
            throw new ShoppingCartNotFoundException();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //SortProduct sp=new SortProduct(new Product());

    Collections.sort(l);
    return l;
}

私の Comparator 実装クラスは次のとおりです

import java.util.Comparator;

import com.bean.Product;


public class SortProduct implements Comparator {

    @Override
    public int compare(Object o1,Object o2)
    {

    Product p1=(Product)o1;

    Product p2=(Product)o2;

    int temp=p1.getName().compareTo(p2.getName());
    return temp;
    }

}
4

2 に答える 2