A Short Exploration of Java Class Pre-Initialization

1. Background

2. Class Pre-Initialization

2.1 Motivation

public class Foo {
private static HashMap<Integer, Integer> cache;
static {
if (cache == null) {
cache = new HashMap<>();
}
for (int i = 0; i < 1024; i++) {
cache.put(i, 0);
}
}
}
public class Foo {
private static HashMap<Integer, Integer> cache; // cache is directly materialized from G1 archive region
static {
// skip execution
}
}

2.2 Class Pre-Initialization Details

2.3 Evaluation

3. Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com