Asking which is the better solution is a bit like asking whether a boat or a bicycle is better. The answer depends on whether there is a road or a river . . .
So it depends on the circumstances which is better. There should be a little about that in
Bloch's Effective Java and probably other books.
Eager initialisation:
Lazy initialisation:
You see
f is only instantiated when it is used. In the eager example,
f was instantiated immediately.