Package org.inferred.freebuilder
Annotation Type FreeBuilder
-
@Target(TYPE) @Retention(SOURCE) public @interface FreeBuilderAnnotates a type that has an auto-generated builder.Quick start
Create your value type (e.g.
Person) as an interface or abstract class, containing an abstract accessor method for each desired field. This accessor must be non-void, parameterless, and start with 'get' or 'is'. Add the@FreeBuilderannotation to your class, and it will automatically generate an implementing class and a package-visible builder API (Person_Builder), which you must subclass. For instance:@FreeBuilder public interface Person { /** Returns the person's full (English) name. */ String getName(); /** Returns the person's age in years, rounded down. */ int getAge(); /** Builder of {@link Person} instances. */ class Builder extends Person_Builder { } }You can now use the
Builderclass:Person person = new Person.Builder() .setName("Phil") .setAge(31) .build(); System.out.println(person); // Person{name=Phil, age=31}