Draft JLS spec for records - local types

Tagir Valeev amaembo at gmail.com
Sat Nov 9 15:31:18 UTC 2019


> Local records should be allowed; we should probably allow local enums at the same time.

On the other hand, local classes also may have an implicit state which
consists of captured variables and possibly captured `this` reference
as well. Usually, all instances of local classes that can interact
with each other have the same captured state, but it's not impossible
to have two instances with the different captured state. E.g.:

public static void main(String[] args) {

static Object foo(int x) {
   class Foo {
      int getX() { return x; }
   if (x == 1) {
      return new Foo();
   Foo foo1 = new Foo();
   Foo foo2 = (Foo) foo(1);
   System.out.println(foo1.getX()); // prints 0
   System.out.println(foo2.getX()); // prints 1
   return null;

If we allow local records, they would also have an implicit state,
that "hidden extra component". E.g. if we define a record without
components instead of class Foo in the example above, its `equals`
method would return true for `foo1` and `foo2`, yet they have
different behavior. Is it still ok?

With best regards,
Tagir Valeev.

More information about the amber-spec-experts mailing list