Why do some folks use Class#method instead of Class.method in correspondence?

雨燕双飞 提交于 2019-11-29 16:15:23

问题


When writing about methods in Java (i.e. in forums, mailing lists, issue trackers, etc.) many people separate the method name from the class name using the '#' symbol instead of Java's native . operator; for example, folks refer to Object#toString instead of Object.toString. Where does this syntax come from?


回答1:


It's the notation used in javadoc comments when linking to another class' method.

EDIT

To gather the additional information provided in comments:

  • @Hugo notes that the # notation in turn comes from HTML anchors
  • @maksimov points out that Object.method is the Java syntax to call static methods, which could be misleading

UPDATE

Java 8 brings a new syntax for method references, which now seems to become more popular - so Object#toString tends to now be written Object::toString.



来源:https://stackoverflow.com/questions/11247793/why-do-some-folks-use-classmethod-instead-of-class-method-in-correspondence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!