-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
None
-
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
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