javasyntaxjava-8java-7lexical

new Java 8+ separators (punctuators) - how/where are they used?


The JLS for Java 8 introduces three new separators:

...   @   ::

The ellipsis (...) is used as "last formal parameter of a method or constructor". But already the JLS for Java 7 described this formal parameter as variable arity parameter. It isn't mentioned as a separator.

The separator :: is used to form method reference expressions.

The @ is meant "to distinguish an annotation type declaration from an ordinary interface declaration" and thus part of an annotation type declaration. Annotations were already part of the JLS for Java 7. I see no other usage for the "at-sign".

Searching for questions and answers about Java 8+ separators I found nothing, which explains the usage of the new separators.

What do the both separators ..., @ separate? How are they used?


Solution

  • First of all, as you note ... was present in Java 7. (I think it was introduced in Java 5!) But with Java 8 they listed it explicitly as one of the "separator" tokens.

    I don't think there is any real significance to that. It is merely an editorial correction.

    What do the both separators ..., @ separate?

    They don't really separate anything. They are classified as "separators" because they are not operators, literals, identifiers or keywords.

    Notes:

    1. In JLS 11 Section 3.1, the spec defines an alternative term "punctuator". Ugly, but more accurate.)

    2. It would not be useful for the JLS to distinguish "separators" that separate from those that don't. The term "separator" is hardly used in the rest of the spec, and certainly not in any context that implies separation.

    3. There is precedent for "separators" not separating. The existing tokens (, ), {, }, [ and ] don't really act as separators either. Their purpose is to start or end constructs.

    4. The < and > tokens are also a bit odd. The lexical grammar calls them operators, but in some contexts they act as (loosely) separators.

    Don't try to read too much into this.