I' have a question about initialization of List in the POJO as it follows the next code:
public class Person {
//other fields...
private List<String> friends=new ArrayList<>();
public List<String> getFriends() {
return friends;
}
public void setFriends(List<String> friends) {
this.friends = friends;
}
}
OR is it better like this and have initalization in other class(like for example Bean(JSF))
public class Person {
//other fields...
private List<String> friends;
public List<String> getFriends() {
return friends;
}
public void setFriends(List<String> friends) {
this.friends = friends;
}
}
So my question is what approach is better?
managedBean
?@PostConstruct
ALL the time. You only need that annotation when and only when you need to wait for some dependency injection to be done so that you can use some services to initialize the list. If not, what you're doing in your question is perfectly fine :). However, I do have a bad feeling that your current architecture is not the best practice. Do you have any entities calledPerson
in the database?