< prev index next >
test/java/lang/Character/UnicodeBlock/NonOptimalMapSize.java
Print this page
rev 11976 : [mq]: XXXXXXX-Remove-INITIAL_CAPACITY-constant
@@ -42,13 +42,18 @@
throw new RuntimeException(
"Character.UnicodeBlock.map is expected to be HashMap");
}
int mapSize = map.size();
- Field sizeField = ubCls.getDeclaredField("INITIAL_CAPACITY");
- sizeField.setAccessible(true);
- int INITIAL_CAPACITY = sizeField.getInt(null);
+ // This is the initial size of Character.UnicodeBlock.map
+ // See src/java.base/share/classes/java/lang/Character.java
+ int INITIAL_CAPACITY = 680; //(int)(510 / 0.75f + 1.0f);
+
+ // We will check that the capacity was sufficient:
+ // - create a new HashMap with this initial capacity
+ // - insert map.size() elements in it
+ // - check that the internal storage wasn't reallocated
// Construct a HashMap with specified initial capacity
HashMap<Object,Object> map1 = new HashMap<>(INITIAL_CAPACITY);
Class<?> hmCls = HashMap.class;
Field tableField = hmCls.getDeclaredField("table");
< prev index next >