Skip to content

Instantly share code, notes, and snippets.

@ohubaut
Created November 15, 2010 20:36
Show Gist options
  • Save ohubaut/700894 to your computer and use it in GitHub Desktop.
Save ohubaut/700894 to your computer and use it in GitHub Desktop.
Try running this in java, you'll obtain 10 as output (autoboxing trap). Run the same in Groovy 1.7.5 will give you 2 as output
import java.util.HashSet;
import java.util.Set;
public class TestAutoboxing {
public static void main(String[] args) {
Set<Short> testSet = new HashSet<Short>();
short counter=0;
while (counter<10)
{
testSet.add(counter);
testSet.remove(counter - 1);
counter++;
}
System.out.println(testSet.size());
}
}
@blackdrag
Copy link

This will most probably change in 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment