Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8184444

The compiler error "variable not initialized in the default constructor" is not apt in case of static final variables

XMLWordPrintable

    • b16

      When there is a final static variable which is not initialized either inline or in a static initializer block, as shown in the example below, the compiler throws an error : "variable x not initialized in the default constructor" .

      From this error, it is difficult to make out the actual cause of the error. The above error makes sense in the case of non-static variable, because it can be initialized in the default constructor if not initialized inline. It should be made more relevant, user-friendly and easily understandable in case of static final variables.

      public class TestFinalVar {
      final static int x;
      public static void main(String[] args) {
           }
      }

            vromero Vicente Arturo Romero Zaldivar
            psonal Pallavi Sonal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: