Yield as contextual keyword

Dan Smith daniel.smith at oracle.com
Fri May 24 16:07:06 UTC 2019

> On May 23, 2019, at 5:51 PM, Alex Buckley <alex.buckley at oracle.com> wrote:
> This policy is "You can declare a method called `yield`, but you can only invoke the method by using qualified invocation syntax." OK, great.
> Could the policy in SE 10 have been similar? -- "You can declare a type called `var`, but you can only declare a variable at the type by using a qualified name." -- `var x = ...` to always indicate LVTI, `com.example.api.var x = ...` to still be possible. The need for TypeIdentifier to kick `var` out of type names (such as the type name used in a LocalVariableDeclarationStatement) would be unnecessary, as the rules of 14.4.1 would special-case the `var` identifier like they do today.

Yes, that's a fair point. A uniform strategy would suggest allowing qualified references to types 'var' and 'yield'. (Specifically: a class or interface declared *in a named package* or *as a member* may be named 'var' or 'yield'; a qualified type name may use 'var' or 'yield' after the dot.)

In 10, that would have seemed like way too much complexity—why bother to allow class declarations named 'var' that can only be referenced with a qualified name? Nobody cares about classes named 'var' anyway.

With 'yield' and method invocations, the story is different—we have useful 'yield' methods in the wild, and need to find a way to continue supporting them.

So, while I don't think that would have been a compelling story in 10, now it may make sense, in order to make our policies more consistent.

More information about the amber-spec-experts mailing list