Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 1.5.6
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Environment:linux
-
Number of attachments :
Description
Running the following code:
def list = [1, 2, 3, 4, 5]
println list[-1] //Displays 5
list.remove(-1) //Throws exception. Should be consistent with above
println list //Never gets here due to exception but the expected output is [1, 2, 3, 4]
produces unexpected results. I would expect list.remove to be able to accept negative indices, just as the [] notation allows me to.
It looks like the correct behaviour to me. The remove method is defined here http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/util/List.html#remove%28int%29 by the Java API. Whilst remove is consistent with Java, [] (on a list) is Groovy with Groovy rules.