Search code examples
javafinal

When should we use an uninitialized static final variable?


When should we use an uninitialized static final variable? I know that an uninitialized static final variable can only be assigned values in the static initializer block, but I can't think of any real use for this.


Solution

  • I assume you mean:

     public static final Object obj;
    

    with no initial value explicitly assigned?

    You can assign it in the static block based on some computation that can only occur at runtime, like reading some property file to create an Application-wide constant that is not known at compile time.