GeezerVison is showing github.com — Add UseListOf and UseSetOf recipes by jkschneider · Pull Request #974 · openrewrite/rewrite-migrate-java
Conversation
jkschneider
commented
Jan 26, 2026
•
edited by moderne-meeseeks
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- Add
UseListOf recipe to convert new ArrayList<>() {{ add(...) }} to List.of(...)
- Add
UseSetOf recipe to convert new HashSet<>() {{ add(...) }} to Set.of(...)
- These recipes complement the existing
UseMapOf recipe for Java 10+ codebases
Test plan
-
Added test cases for field-level and method-level double-brace initialization
-
Added test cases for single and multiple elements
-
Added test cases for non-string types and constants
-
Added test cases verifying no change when constructor has arguments
-
Added test cases verifying no change when block contains non-add statements
-
All tests pass locally
-
Fixes: moderneinc/customer-requests#1544
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add recipes to convert double-brace initialization of ArrayList and
HashSet to List.of() and Set.of() respectively for Java 10+. These
recipes complement the existing UseMapOf recipe.
Example transformation for UseListOf:
new ArrayList<>() {{ add("a"); add("b"); }}
becomes
List.of("a", "b")
Example transformation for UseSetOf:
new HashSet<>() {{ add("a"); add("b"); }}
becomes
Set.of("a", "b")
Fixes: moderneinc/customer-requests#1544
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.