実行時に次のプションが必要
–add-opens java.base/java.util=ALL-UNNAMED
import java.lang.reflect.Field;
import java.util.HashMap;
public class Test {
public static void main(String[] args) throws Exception {
HashMap<String, String> map = new HashMap<>();
map.put("one", "1");
map.put("two", "2");
map.put("three", "3");
// リフレクションを使用して内部テーブルのサイズを取得
Field tableField = HashMap.class.getDeclaredField("table");
tableField.setAccessible(true);
Object[] table = (Object[]) tableField.get(map);
// テーブルのサイズを表示
System.out.println("内部テーブルのサイズ: " + table.length);
}
}