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
.