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

2019-02-16 22:51发布

3条回答
该账号已被封号
2楼-- · 2019-02-16 23:04

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

查看更多
Lonely孤独者°
3楼-- · 2019-02-16 23:20

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).

查看更多
成全新的幸福
4楼-- · 2019-02-16 23:23

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.

查看更多
登录 后发表回答