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

Redundant static modifier for records creates unnecessary confusion

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Records seem to be static per default, but there still seems to be the option to add a static modifier that doesn't change anything.
      For example, if a record (with or without a static modifier) is used within a class, like in the attached example, it produces the error: non-static variable m cannot be referenced from a static context.
      In contrast, if a normal internal (non static) class is used, it works without problems.
      It would be good to not allow this modifier when a record is created, since it only adds unnecessary confusion.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      class ClassTest{
      int m = 1;
      static int s =2;

      class NClass{
      public void get(){
      System.out.println(m+" "+s);
      }
      }

      record NRec(){
      public void get(){
      System.out.println(m+" "+s);
      }
      }
      }


      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: