You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
If generating public build, buildPartial, clear or mergeFrom methods would cause a compiler error, instead make them package-protected and, if necessary, find an alternative method name by prepending an underscore and appending Impl and optionally a number.
Copy file name to clipboardexpand all lines: README.md
+21
Original file line number
Diff line number
Diff line change
@@ -533,6 +533,27 @@ For instance, `assertEquals` in JUnit relies on equality; it will not know to ch
533
533
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.
534
534
Alternatively, creating a custom [Comparator] will make it explicit that you are not using the natural definition of equality.
535
535
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
+
publicinterfaceMyType {
542
+
classBuilderextendsMyType_Builder {
543
+
publicOtherDataTypebuild() {
544
+
// This signature is not compatible with the default build method.
545
+
// FreeBuilder will instead declare a package-scoped _buildImpl.
546
+
...
547
+
}
548
+
publicDataTypebuildMyType() {
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
+
536
557
### Custom functional interfaces
537
558
538
559
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