I have code that creates a List initialized with map size:
private Set<String> mKeys = new HashSet<String>(64);
....
List<String> keyList = new ArrayList<String>(mKeys.size());
I see an exception: java.lang.IllegalArgumentException: Invalid capacity: -1
Can a card return a size of -1? I am looking at the source code for a HashSet that is supported by HashMap. The source code for the HashMap shows the insides where elementCount is always reduced by a call to removeEntry (). In addition, the HashMap.empty () response methods to elementCount are == 0, which return false if elementCount is -1.
Has anyone come across this before? I can encode it, but it seems like a hack, which makes me think that I am doing something wrong with the current code.
EDIT: I tried to simplify the task first. The set that I use is actually defined as
private static Set<String> mKeys = Collections.synchronizedSet(new HashSet<String>(64));
EDIT: synchronizedSet. JavaDoc:
, :
Set s = Collections.synchronizedSet(new HashSet());
...
synchronized(s) {
Iterator i = s.iterator();
while (i.hasNext())
foo(i.next());
}
.
-1. , , , .