运行代码时出现以下错误我应该在编写此方法的类中创建类 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;
}
}