Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-5777

Static initializers not running in NetBeans with java 16

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 12.4
    • None
    • None
    • None
    • Windows 10 Pro

      openjdk version "16.0.1" 2021-04-20

      OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)

    Description

      When running a project from the IDE, static initializers never seem to run.

      For example:

      public class StaticInitializerTest{
          public static String str;
          static{
              System.out.println("Static initializer has run!");
              str = "set";
          }
          public static void whatIsStr(){
              System.out.println(str);
          }
          public static void main(String[] args) {
              whatIsStr();
          }
      }
      

      When run from in the IDE, the output reads

      null

      When run from the command line, the output reads

      Static initializer has run!
      set

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            ThizThizzyDizzy James Dolan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: