In the class containing the target: A builder() method, which creates a new instance of the builder.Įach listed generated element will be silently skipped if that element already exists (disregarding parameter counts and looking only at names). In the builder: A sensible toString() implementation. It returns the same type that the target returns. In the builder: A build() method which calls the method, passing in each field. It returns the builder itself, so that the setter calls can be chained, as in the above example. In the builder: A 'setter'-like method for each parameter of the target: It has the same type as that parameter and the same name. In the builder: A package private no-args empty constructor. In the builder: One private non-static non-final field for each parameter of the target. While the "on a class" and "on a constructor" mode are the most common use-case, is most easily explained with the "method" use-case.Ī method annotated with (from now on called the target) causes the following 7 things to be generated:Īn inner static class named FooBuilder, with the same type arguments as the static method (called the builder).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |