Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to refer to Java members in text?

Tags:

java

In answering questions I find myself referring to method names and online documentation often. I'm confused about how method names should be referenced in text.

For example I often type:

One should use String.equals() for comparing two strings for equality.

However, this is a little misleading:

  1. It makes equals() appear to be a static member.
  2. It makes equals() appear to not take any arguments.

In the interest of compleness, I would like to know:

What is the correct way to refer to both static members and instance members?

I've seen things like:

  • String.equals()
  • String#equals()
  • myString.equals()

Is there a way to refer to methods in an argument-agnostic manner?

For example, in C foo(void) is explicitly a zero-argument function and foo() can be redefined later to have a different set of arguments. (?)

like image 436
Matthew Willis Avatar asked Mar 10 '11 19:03

Matthew Willis


2 Answers

If you want to be really be exact you could use

java.lang.String#equals(java.lang.Object)

or the shorter form

String#equals(Object)

This is similar to the notation used in javadoc and interestingly also looks similar to the link to the documentation which ends with:

String.html#equals(java.lang.Object)

Edit: Here is a link to the javadoc documentation describing how to use references.

like image 176
Jörn Horstmann Avatar answered Sep 23 '22 11:09

Jörn Horstmann


I've found that a link to the documentation for String's equals method removes the ambiguity.

like image 41
Bill the Lizard Avatar answered Sep 22 '22 11:09

Bill the Lizard