-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Labels
Description
Problem
In checkstyle/checkstyle#14229 we are enabling the CollectorMutability check in the Checkstyle repository. The Checkstyle team tries to minimize the dependencies they have on Guava. Therefore, the rewrite to Immutable{List,Map,Set}.toImmutable{List,Map,Set}() is not desirable. An alternative would be to use the Collectors.toUnmodifiable{List,Map,Set}(). This is a good alternative as this also clearly communicates that a list is used that should not be modified.
Description of the proposed new feature
- Support a stylistic preference.
- Avoid a common gotcha, or potential problem.
- Improve performance.
I would like to rewrite the following code:
.collect(Collectors.toSet());to:
.collect(Collectors.toUnmodifiableSet());Considerations
Two things:
- As @Stephan202 notes, this should take into account that this rewrite is only valid when JDK > 9.
- This XXX in
ThirdPartyLibraryshould be resolved as well.
Participation
- I am willing to submit a pull request to implement this improvement.
Stephan202