Contextual Keywords in Java
Contextual keywords formerly known as restricted identifiers and restricted keywords. contextual keywords are identified based on where they will appear in the syntactic grammar.
These are the keywords that provides the specific meaning in the code. These are not reserved keywords like abstract, new, final, try, import, etc.
Character sequences, formed from ASCII characters, are reserved for use as keywords that cannot be used as identifiers. Another 12-character sequences, also formed from ASCII characters, may be interpreted as keywords, depending on the context in which they appear.
So, reserved keywords and contextual keywords are two different things.
There are the following reserved keywords in Java:
Following are the contextual keywords in Java:
A character sequence matching a contextual keyword is not treated as a keyword if any part of the sequence can be combined with the immediately preceding or following characters to form a different token.
So, the character sequence openmodule is interpreted as a single identifier rather than two contextual keywords, even at the start of a ModuleDeclaration. If two keywords are intended, they must be separated by whitespace or a comment.
We are being intentionally vague about how an implementation might disambiguate. The above note should be enough to make clear that this is an implementation choice, not something we're going to specify explicitly. Still, as the language evolves, designers will need to be careful about the implementation impact of new contextual keywords in certain contexts.
A variety of character sequences are sometimes assumed, incorrectly, to be keywords:
The meaning of a name depends on the context in which it is used. The determination of the meaning of a name requires three steps:
The use of context helps to minimize name conflicts between entities of different kinds. Such conflicts will be rare if the naming conventions described in 6.1 are followed. Nevertheless, conflicts may arise unintentionally as types developed by different programmers or different organizations evolve. For example, types, methods, and fields may have the same name. It is always possible to distinguish between a method and a field with the same name, since the context of a use always tells whether a method is intended.
Identifiers that act as keywords only in specific language structures. The difference with keywords is that context keywords can be used as identifiers in other parts of the code. Certain context keywords (such as partial and where) have special meanings in two or more contexts.