Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bar {
- private static class BarHolder {
- static {
- System.err.println("BarHolder initialization");
- }
- public static Bar bar = new Bar();
- }
- public static Bar getBar() {
- return BarHolder.bar;
- }
- public Bar() {
- System.err.println("complex Bar ctor running");
- }
- public static void main (String[] args) {
- System.err.println("fetching a Bar");
- Bar some_bar = Bar.getBar();
- System.err.println("fetching another Bar");
- Bar another_bar = Bar.getBar();
- System.err.println("done");
- }
- }
- /*
- Running with "java Bar" :
- fetching a Bar
- BarHolder initialization
- complex Bar ctor running
- fetching another Bar
- done
- Running with "java -verbose:class Bar" :
- [...several hundred lines of JRE loading...]
- fetching a Bar
- [Loaded Bar$BarHolder from file:/C:/src/] <-- delayed loading
- BarHolder initialization
- complex Bar ctor running
- fetching another Bar
- done
- [Loaded java.lang.Shutdown from C:\....\rt.jar]
- [Loaded java.lang.Shutdown$Lock from C:\....\rt.jar]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement