Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 1eedb99

Browse files
committed
Document ability to change name of conventional methods
1 parent e6e4654 commit 1eedb99

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,27 @@ For instance, `assertEquals` in JUnit relies on equality; it will not know to ch
533533
If you are only testing a subset of your fields for equality, consider separating your class in two, as you may have accidentally combined the key and the value of a map into a single object, and you may find your code becomes healthier after the separation.
534534
Alternatively, creating a custom [Comparator] will make it explicit that you are not using the natural definition of equality.
535535

536+
### Custom conventional method names
537+
538+
If for any reason your types cannot use the conventional method names (`build`, `buildPartial`, `clear` and `mergeFrom`), you can force FreeBuilder to generate package protected implementations, and even select alternative fallback names if necessary, by declaring an alternative visibility and/or incompatible signature. If the default name is not available, FreeBuilder will prepend an underscore and append "Impl" (and, if necessary, a number), e.g. `build` becomes `_buildImpl`.
539+
540+
```java
541+
public interface MyType {
542+
class Builder extends MyType_Builder {
543+
public OtherDataType build() {
544+
// This signature is not compatible with the default build method.
545+
// FreeBuilder will instead declare a package-scoped _buildImpl.
546+
...
547+
}
548+
public DataType buildMyType() {
549+
return _buildImpl();
550+
}
551+
}
552+
}
553+
```
554+
555+
Note that this will, unfortunately, disable FreeBuilder's [enhanced support for nested builders](#nested-buildable-types) for this type, as it needs to be able to call these methods.
556+
536557
### Custom functional interfaces
537558

538559
FreeBuilder's generated map and mutate methods take [UnaryOperator] or [Consumer] functional interfaces. If you need to use a different functional interface, you can override the generated methods in your Builder and change the parameter type. FreeBuilder will spot the incompatible override and change the code it generates to match:

0 commit comments

Comments
 (0)