Recipe for collection.toArray(new Foo[collection.size()]) #3590
Replies: 1 comment
-
Hi! Thanks for the suggestion (and other activities)! Fully agree with this suggestion; I'd logged that as a recipe suggestion here: If you want an easy way to search across issues for all OpenRewrite projects then I recommend: Hope that helps! We can continue the the discussion around this recipe in openrewrite/rewrite-static-analysis#84 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When converting collections to arrays, many people still write
collection.toArray(new Foo[collection.size()])
in an attempt to optimize the allocation of the new array. However, using...new Foo[0]
is not slower on current JVMs, and more easy to read. There should be some recipe to implement this cleanup.Detailed technical background: https://shipilev.net/blog/2016/arrays-wisdom-ancients/
(And I'm not sure if I should instead raise a feature request, not a discussion topic)
Beta Was this translation helpful? Give feedback.
All reactions