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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 20
    • 19
    • tools
    • None
    • b18

    Description

      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";
      |

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              sundar Sundararajan Athijegannathan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: