Rule: UseArraysAsList
I think there's a real problem with this rule though. It flags cases where we add the contents of an array to a List. But if the list was not empty in the beginning, or if you want to add other elements later, then you can't use Arrays::asList
because it's fixed size. Sure, you could do list.addAll(Arrays.asList(yourArray))
. But a better fix is Collections.addAll(list, yourArray)
. I would suggest we rename the rule AddCollectionInBulk
, and enhance the doc to point to Collections::addAll
(and also Arrays::asList
, but with the above caveat). We can also detect loops where instead of looping on an array, we loop on another collection (and call Collection::get). Finally, both when looping on an array or on another collection, we should support foreach loops.
Originally posted by @oowekyala in #3187 (comment)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4