Initialization of List in a JSF Managed bean

后端 未结 5 953
闹比i
闹比i 2020-12-01 13:19

I\' have a question about initialization of List in the POJO as it follows the next code:

public class Person {

 //other fields...
 private List

        
5条回答
  •  伪装坚强ぢ
    2020-12-01 13:30

    In my opinion it would be best to handle that in the constructors. If a default constructor is used, initialize the list in the constructor.

    public Person() {
        friends = new ArrayList<>();
    }
    

    If a constructor which accepts parameters is used, let the calling class pass in a list.

    public Person(ArrayList<> friends) {
        this.friends = friends;//friends
    }
    

提交回复
热议问题