gpt4 book ai didi

java - MyType#myMethod() 中的 "#"是什么意思以及与 MyType.myMethod() 中的 "."的区别

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:46:43 25 4
gpt4 key购买 nike

嗯,一切都在标题中......

我知道这两种形式都引用了该方法,但我看不到 # 添加到另一种形式的内容。

最佳答案

哈希字符 (#) 不是 Java 语言的一部分。

它在 javadoc 中有特殊用途。 specification

package.class#member is any valid program element name that is referenced -- a package, class, interface, constructor, method or field name -- except that the character ahead of the member name should be a hash character (#).

As stated, the hash character (#), rather than a dot (.) separates a member from its class. This enables the Javadoc tool to resolve ambiguities, since the dot also separates classes, nested classes, packages, and subpackages. However, the Javadoc tool is generally lenient and will properly parse a dot if you know there is no ambiguity, though it will print a warning.

该表示法不仅适用于方法,它适用于任何类型成员。它有助于消除完全限定类型名称中的歧义。

关于java - MyType#myMethod() 中的 "#"是什么意思以及与 MyType.myMethod() 中的 "."的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24354882/

25 4 0