What is the name of the :: operator in Java 8

前端 未结 3 1104
故里飘歌
故里飘歌 2021-01-12 04:26

I can\'t find the name of the :: operator added in Java 8 in either of the following resources:

  • Proposed Final Draft Specification: The Java Langu
相关标签:
3条回答
  • 2021-01-12 04:41

    It should probably be called a "colon colon separator":

    • Brian Goetz* calls it "colon colon" and since he was the specification lead for the lambda JSR I suppose we can consider him as an authoritative source.
    • The specification #3.11 classifies :: as a separator.

    *source: the road to lambda @ Javaone 2013 around 04:00.

    0 讨论(0)
  • 2021-01-12 04:42

    It's described as a 'separator' in both #3.11 and #15.13.3.

    0 讨论(0)
  • 2021-01-12 04:44

    As per here, it looks like it's called a method reference operator. It's covered in section 15.13 of the proposed JLS you link to.

    However, as rightly pointed out, it appears to be never explicitly named as an operator (unlike all the things like +, - and so on). Instead, the JLS simply refers to the entire expression containing :: as a method reference expression.

    It may be that this is because :: is not considered to be an operator at all but is explicitly called out as a separator (see JLS link 3.11, while the operators are in 3.12).

    So I would tend to call it, in the context you're interested in, a method reference separator (or, more generally, the double-colon separator).

    0 讨论(0)
提交回复
热议问题