凡是属性中有Set的都直接声明中直接new出来

来源:互联网 发布:诺基亚500软件 编辑:程序博客网 时间:2024/05/14 13:58

凡是属性中有Set的都直接声明中直接new出来,避免后面出现空指针异常,比如:

public class Department {private Long id;private String name;private String description;private Department parent;private Set<Department> children = new HashSet<Department>();private Set<User> users = new HashSet<User>();