Deconstruction but no destructuring when declaring local variables

Remi Forax forax at univ-mlv.fr
Tue Apr 7 18:20:03 UTC 2020


There was discussions about the danger of only providing instanceof + the deconstruction pattern and not a way to have the same kind of destructuring when declaring local variables

By example, instead of
  Point p = ...
  int x = p.x();
  int y = p.y();
  
one can write
  Point p = ...
  if (!(p instanceof Point(int x, int y)));

I think we should restart those discussions because variables declarations is like a third places where patterns can appear (instanceof and switch being the other two).

I don't really want to propose a syntax, so the next examples will be to give an idea of the semantics
The idea is to allow patterns on the left side of an '='.
So
  pattern = value;

We already have
  Point p2 = p;  // the type pattern

so if we expand it with the new patterns proposed for instanceof, we get
  Point(int x, int y) = p;   // the deconstruction pattern with explicit type
and
  Point(var x, var y) = p;   // the deconstruction pattern with var

regards,
RĂ©mi





  



More information about the amber-spec-experts mailing list