I am generating the Java from XML. The setters all return void. If they returned "this", then they could be called in a chain. Is there a way ( an easy way ) to make it generate setters that "return this;" ?
Asked
Active
Viewed 606 times
2 Answers
4
Take a look at the JAXB Fluent API Plugin.
USAddress address = new USAddress()
.withName(name)
.withStreet(street)
.withCity(city)
.withState(state)
.withZip(new BigDecimal(zip));

lexicore
- 42,748
- 17
- 132
- 221
3
What you are talking about is the builder pattern. If you are interested in generating classes from XML that have the additional setter methods returning this for chaining, take a look at the following post: Is there a JAXB Plugin which generates Builders?