Builder pattern for polymorphic object hierarchy: possible with Java?
问题 I have a hierarchy of interfaces, with Child implementing Parent . I would like to work with immutable objects, so I would like to design Builder classes that construct these objects conveniently. However, I have many Child interfaces, and I don't want to repeat the code for building Parent s in each type of child builder. So, assume the following definitions: public interface Parent { public Long getParentProperty(); } public interface Child1 extends Parent { public Integer getChild1Property