Issue
Prior to Java 8, my observation was that the de facto standard for referring to member methods was by using the #
symbol (such as Object#toString()
). Then along came Java 8 which instead chose the ::
operator for method references for seemingly no reason.
Has there been an official explanation or justification for why ::
in particular was chosen?
Solution
You could find an "official explanation or justification" from Brian Goetz. You should read the complete discussion but this is an extract :
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.)
Answered By - gontard Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.