Yield as contextual keyword
Tagir Valeev
amaembo at gmail.com
Sun May 26 04:47:23 UTC 2019
Sure the problem could be fixed in a number of ways, it's just not as
straightforwards as adding a qualifier. I can also think up several
ways to fix this locally (modifying just single line):
((Runnable)() -> yield(1)).run();
or
switch(0) { default -> yield(1); }
or even
for(int i=0; i<1; yield(1), i++) {}
With best regards,
Tagir Valeev
On Sun, May 26, 2019 at 3:22 AM John Rose <john.r.rose at oracle.com> wrote:
>
> This one is fixable with a local-variable rename.
> I think that's a robust solution as long as the
> anonymous class is in a context where the
> local can be introduced nearby.
>
> We can perhaps find awkward contexts where
> the local cannot be introduced. I'm thinking
> of 'super(new Object() {…})' and field initializers.
> In those cases, the outer object can supply
> a field or method to provide access to the
> shadowed 'this'.
>
> On May 24, 2019, at 11:15 PM, Tagir Valeev <amaembo at gmail.com> wrote:
> >
> >
> > var x = new Runnable() {
> > public void run() {
> + var this1 = this;
> > new Object() {
> > void foo() {
> + this1.
> > yield(1); // this.yield(1) or Runnable.this.yield(1) are incorrect.
> > }
> > }.foo();
> > }
> > void yield(int x) { System.out.println(x); }
> > };
>
More information about the amber-spec-experts
mailing list