在Java文献中,”#”符号代表什么意思?

huangapple go评论116阅读模式
英文:

What does # symbol mean in Java literature?

问题

我注意到在Java文献中常常使用**#**符号。它是否表示类实例的方法?这是一种标准还是约定?以下是该符号被使用的示例:

《Spring Boot持久化最佳实践》(第3章,第150页)
> // 在幕后它调用了EntityManager#merge()

《Spring Boot参考文档》(第4.25.3章,第82页)
> 或者,您可以使用@ImportAutoConfiguration#exclude

英文:

I've noticed that the # symbol is commonly used in Java literature. Does it denote methods of class instances? Is this some kind of standard or convention?

Here are examples of this symbol being used:

Spring Boot Persistence Best Practices (ch 3, page 150)
> // behind the scene it calls EntityManager#merge()

Spring Boot Reference Documentation (ch 4.25.3, page 82)
> Alternatively, you can use @ImportAutoConfiguration#exclude.

答案1

得分: 3

它过去常用于表示类与方法之间的界限,很类似于方法引用运算符 ::

EntityManager#merge() 表示类 EntityManagermerge 方法。因为存在重载,有时必须包含参数的类型以消除任何歧义,但有时可以省略。在这种情况下,我们可以看到该方法没有参数。

从这种表示法无法判断它是静态方法还是实例方法,其修饰符是什么等等。它的使用方式类似于URI 片段;它更像是指向所讨论的方法的路标。

你会发现它也用于字段和注解类型元素,但方法是最常见的。


<sub>
<span>*</span> 昨天我学到这被称为“Paamayim Nekudotayim”。<a href="https://en.wikipedia.org/wiki/Scope_resolution_operator">现在你也知道了</a></sub>

英文:

It used to denote the delineation between a class and a method, much like the method reference operator :: *.

EntityManager#merge() means the merge method of the class EntityManager. Because overloading exists, sometimes the types of the parameters are necessarily included to remove any ambiguity, but sometimes they are omitted. In this case, we can see the method has no parameters.

There is no way to tell from this notation whether it's a static or instance method, what its modifiers are, etc. It is used in similar way to a URI fragment; it is designed to act more like a signpost to the method in question.

You see it used for fields and annotation type elements too but methods are the most common.


<sub>
<span>*</span> I learned yesterday that this is called "Paamayim Nekudotayim". <a href="https://en.wikipedia.org/wiki/Scope_resolution_operator">Now you know</a></sub>

答案2

得分: 1

Sure, here is the translated content:

`#` 表示类成员或方法。

这非常有用,因为它允许您为Java代码提供更好的文档(即:javadocs)

示例:

public class Dog {
    private String name;

   // ...

   /**
    * 使用狗的名字和叫声来返回狗的描述。
    *
    * @see Dog#name
    * @see Dog#bark()
    */
    public String getDescription() {
       // ...
    }

    public String bark() {
       // ...
    }
}

请注意,我只翻译了您提供的代码部分。如果您还有其他需要翻译的内容,请继续提供。

英文:

# refers to class members or methods.

It is very useful because it allows you to specify better documentation for Java code in general (i.e.: javadocs)

Example:

public class Dog {
    private String name;

   // ...

   /**
    * Returns the dog&#39;s description using it&#39;s name and how it barks.
    *
    * @see Dog#name
    * @see Dog#bark()
    */
    public String getDescription() {
       // ...
    }

    public String bark() {
       // ...
    }
}

答案3

得分: 1

对于所有的Java应用程序,#被用在.properties文件中来注释一行。

你提到的例子只是一种表示方法的约定,例如String#split可以用来表示类Stringsplit函数。

英文:

For all Java applications, # is used in a .properties file to comment out a line.

The example which you have mentioned is just a convention for denoting a method e.g String#split can be used to denote the split function of the class, String.

答案4

得分: 0

这是一个应该被铲除的邪恶之源。井号符号(#)的使用是从基于HTML的文档中泄漏到主流书面文本中的。这是极为严重的,因为已经有完全有效的方法来编写与实际在语言中使用的类方法调用和属性相匹配的内容。为什么要写“EntityManager#merge()”,而“EntityManager.merge()”已经是良好的Java代码呢?

我不知道为什么会出现这些偏爱,但应该予以抵制。天晓得,编程已经够难的了,不需要在文档中引入有问题的语言语法。

英文:

It's an evil scourge that should be stamped out. The # notation is a leakage from HTML-based documentation into mainstream written text. It's egregious because there are already perfectly good ways of writing class method calls and attributes, that match those actually used in the language. Why write "EntityManager#merge()" when the "EntityManager.merge()" is already good Java?

I don't know why these affectations break out, but they should be resisted. Goodness knows, programming is difficult enough, without introducing dysfunctional language syntax into documentation.

huangapple
  • 本文由 发表于 2020年9月21日 19:27:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63991342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定