小编Kir*_*abu的帖子

Beancomparator不使用空值

我的要求是根据customername该bean中的属性对Customer类型bean的列表进行排序...对于我使用过的.beancomparatorcustomername字段不是时,它正常工作null.NullPointerException这场比赛是投掷null..请帮助我...

我的代码是

public class customer{
private String customername;
}

main()
{
list<customer> list=new arraylist();
//list is filled with customertype beans
comparator<customer> comp=new beancomparator(customername);
collections.sort(list,comp);//throwing error when customername is null...
}
Run Code Online (Sandbox Code Playgroud)

java

5
推荐指数
2
解决办法
2210
查看次数

标签 统计

java ×1