-1

I've got a class with only static members, designed like that:

public class Clazz {

    public static final Foo foo = FooFactory.createFoo();

    private static Bar bar;

    public static void prepare() {
        bar = new Bar(foo);
    }
}

When calling Clazz.prepare(), I can see that foo is null at bar initializing. As far as I know, static initializer should be invoked just before the invocation of any static method of the class. Therefore, foo should already be initialized when prepare() is called. Am I missing something?

basme
  • 81
  • 9

2 Answers2

1

FooFactory.createFoo() must be returning a null value

Rafik BELDI
  • 4,140
  • 4
  • 24
  • 38
-1

Actually, initializer of Foo calls Clazz.prepare() too. That's the reason. Thanks @biziclop for the idea.

basme
  • 81
  • 9