Open delanym opened 4 months ago
getLast()
should work when a variable is used, but with method calls we hadn't yet covered those out of caution. In theory there might be side effects to that method call, hence why we're being safe. While it ought to be rare that folks call a method twice and expect a different collection, we can't rule it out and hence have to opt for the safest mode of not making code changes.
The recipe at https://docs.openrewrite.org/recipes/java/migrate/util/sequencedcollection can recognize a match where a simple index value is used
but it misses code where the size of the collection being operated on is given (which an Intellij inspection will convert) such as
or even where a constant is used, such as
Calculating the index based on a constant value may be asking too much.