为什么有些人在通信中使用Class#方法而不是Class.method? [英] Why do some folks use Class#method instead of Class.method in correspondence?

查看:130
本文介绍了为什么有些人在通信中使用Class#方法而不是Class.method?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中编写方法时(即在论坛,邮件列表,问题跟踪器等中),许多人使用#符号而不是Java的本机将方法名称与类名分开。 运营商;例如,人们引用 Object#toString 而不是 Object.toString 。这个语法来自哪里?

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?

推荐答案

这是链接到另一个类'方法时javadoc注释中使用的符号。

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

编辑

收集评论中提供的其他信息:

To gather the additional information provided in comments:


  • @Hugo注意到表示法依次来自HTML锚点

  • @maksimov指出那个 Object.method 是调用静态方法的Java语法,这可能会产生误导

  • @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为方法引用带来了一种新语法,现在它似乎变得更受欢迎 - 所以 Object#toString 现在倾向于写成 Object :: toString

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.

这篇关于为什么有些人在通信中使用Class#方法而不是Class.method?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆