In an article on double checking idiom blocking, I found this quote:
One special case of lazy initialization, which works as expected without synchronization, is a static singleton. When an initialized object is a static class field without any other methods or fields , the JVM automatically performs lazy initialization.
Why is the important part important? Why doesn't it work if other methods or fields exist?
(The article is over 10 years old. Is the information still relevant?)
, , , , , . , ,
class Foo { public static final Foo foo = new Foo(); public static int x() { return 0; } } class AnotherClass { void test() { print(Foo.x()); } }
, foo , .
foo
/, .