addAll to Set is not adding the values in java

I have a property in an Object(Obj1) Set serviceList; public Set getServiceList(); I am doing the below operation in certain instances Obj1.getServiceList().clear(); Obj1.getServiceList().addAll(services); where Services is also Set But what I see as an end result is services set is having 4 objects/data elements but Obj1.getServiceList() is returning an empty set after addAll What's the issue here. is it a problem with AssignedService object since it doesn't implements IComparable
Yes it would be good the implement Comparable (and nice to have correct methods for equals and hashCode). You can check services.size(). Should be 0. Otherwise I would have expected at least one element. Maybe you ignore Exceptions somewhere in an empty catch. You did not initialize with Collections.emptySet() which is read-only?

以上就是addAll to Set is not adding the values in java的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准