Open lpfeup opened 6 years ago
The current behavior is intended: mutable builder for best performance with limited allocations.
Would you be willing to accept a pull request?
Maybe introduce a second ImmutableRequestBuilder
?
Just for clarification, ImmutableRequestBuilder
would still be mutating it's internal state on each method call. But it would no longer modify objects passed as arguments from calling methods.
Is that it?
No, please go with full immutability.
Similar to Scala case classes.
the
addQueryParams
/setQueryParams
methods are assigning the passed argument directly to the class fieldqueryParams
. This has unwanted side-effects.Code:
RequestBuilderBase.addQueryParams
RequestBuilderBase.setQueryParams
Example:
Another example:
I suggest replacing the assignments
queryParams = params
with copies as below:Would you be willing to accept a pull request?