在Java 8之前,我观察到指称成员方法的事实标准是使用“#”符号(例如Object#toString())。然后Java 8推出了“::”运算符作为方法引用,而似乎没有明确的原因选择这种方式。官方有解释或理由吗?
The :: infix syntax:
ClassName::methodName ClassName<T>::methodName ClassName::<U>genericMethodName
works acceptably well. Some people like it, and some people hate it -- just like #. There's never going to be a perfect syntax for anything that makes everyone jump up in unison and say "yeah, that's it!" But :: is OK, and using up :: here is far better than using up #. (And, while this might look a little weird to C++ programmers, the overlap between the Java and C++ developer bases at this point is small enough that I don't think we should be too worried about that.)
#
来引用成员方法? - Kayaman::
只是被借用来定义一个方便的方法引用方式,左边部分是它的类或实例,右边部分是方法名。 - fge