I have a class that stores many fields (both primitive types and objects like String
or List
). All fields are required and need to be set only once, when the object is created.
What is the correct way to instantiate this using Lombok while ensuring these conditions are met:
1) No warnings due to risk of mutable objects being returned by Setters.
2) Do not use a constructor to instantiate all fields, since number of fields can be >10.
3) Be able to inherit and extend this class, where each subclass will only add more fields, and do nothing else.
4) Be serialization friendly (i.e., have an empty public constructor).
class ParentData {
int id;
String name;
}
class ChildData extends ParentData {
long childId;
long[] friendId;
String[] friendNames;
}
Currently, even if I set the fields as private final
, I get findBugs errors that the []
objects are mutable.