jshell reports error on initialisation of static final field of anonymous class

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 20
    • Affects Version/s: 19
    • Component/s: tools
    • None
    • b18

      File: Main.java

      public class Main {
        public static void main(String[] a) {
          var obj = new Object() {
            public static final String msg = "Hello";
          };
          System.out.println(obj.msg);
        }
      }

      $ java Main.java
      Hello

      $ jshell
      | Welcome to JShell -- Version 19
      | For an introduction type: /help intro

      jshell> var obj = new Object() {
         ...> public static final String msg = "hello";
         ...> }
      | Error:
      | cannot assign a value to final variable msg
      | public static final String msg = "hello";
      |

            Assignee:
            Jan Lahoda
            Reporter:
            Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: