Suppose you create a class names Person using the builder pattern, and suppose the Builder class contains methods body(), head(), arms() and of course build() and you consider methods head() and build() obligatory for the user of this class.
We would like to somehow mark these methods obligatory, if possible using annotations. If a user of this class tries to build a Person instance but forgot to call either of these methods, we would like to get some kind of warning – either from the java compiler, or maybe from Eclipse or Maven, which we use to build our projects – any of them would do.
Is it possible to do? Which way would you suggest?
Here is an example with using different types to make some parts mandatory (it also makes the order you call the methods mandatory):
Edit
The OP was so impressed with this answer that he wrote it up fully in a blog. It’s such a clever take on the builder pattern that a full treatment deserves to be referenced here.