A small remark: when we advice to qualify the `yield` call to distinguish it from YieldStatement, there's one corner case when qualification is impossible. I mean a nested class inside an anonymous class
var x = new Runnable() { public void run() { new Object() { void foo() { yield(1); // this.yield(1) or Runnable.this.yield(1) are incorrect. } }.foo(); } void yield(int x) { System.out.println(x); } }; I admit that such code is completely insane and probably doesn't exist anywhere on the planet. Yet, the spec draft says: > Any statement that begins with a reference to a field or method called yield > can use its qualified name to ensure that the character sequence is not > tokenized as a keyword. Here 'Any' is not entirely correct. With best regards, Tagir Valeev. On Sat, May 25, 2019 at 1:05 PM Tagir Valeev <amae...@gmail.com> wrote: > > Hello! > > On Sat, May 25, 2019 at 4:44 AM Alex Buckley <alex.buck...@oracle.com> wrote: > > On the other hand, the space after `:` is sometimes desirous of an > > expression, so tokenize `yield` as a identifier: (and it might be the > > name of a local variable, so no way to qualify) > > > > - `for (String s : yield . f) ...` > > > > - `m(a ? yield . f : yield . g)` > > Well to me it seems that `:` is no more special here than other listed > tokens (probably except `}`). E.g.: > > - After `)`: ((Foo)yield).bar(); > - After `{`: Object[] arr = {yield}; > - After `;`: for(int i=0; i<10; yield(i++)) {} > > `yield` keyword is always preceded by one of X, Y, Z tokens doesn't > mean that any `yield` character sequence which follows X, Y or Z > tokens is necessarily a keyword. Only where YieldStatement production > is expected we treat it as a keyword. > > Btw `yield` keyword can also appear after `else` token: if(foo) yield > bar; else yield baz; > > With best regards, > Tagir Valeev.