June 2018
Intermediate to advanced
280 pages
7h 46m
English
The Lombock library introduces the builder as part of its features. By just using the @Builder annotation, any class can automatically gain access to a builder method, as the Lombock example code shows at https://projectlombok.org/features/Builder:
Person.builder().name("Adam Savage").city("San Francisco").job("Mythbusters").job("Unchained Reaction").build();
Other pre-Java 8 implementations made use of reflection to create a generic builder. The Java 8+ generic builder version can be implemented by leveraging the supplier and the BiConsumer composition, as shown in the following code:
jshell> class Person { private String name;...> public void setName(String name) { this.name = name; }...> public String getName() { return name; }} ...Read now
Unlock full access