Search code examples
javajavadoc

What is the difference between `.` and `#` in the JavaDoc?


I have this line in Javadoc above method:

* {@link client.navigator.URLManager.newToken(NavigationToken)}

and Intellij IDEA analyzer highlights it as error:

Cannot resolve symbol 'client.navigator.URLManager.newToken'

but if I change . to # it is ok.

* {@link client.navigator.URLManager#newToken(NavigationToken)}

What is the difference? Because I have a lot of places with . and with # in the project.


Solution

  • . separates parts of the package and the package from the class.

    # separates class names from fields, methods or constructors.

    I.e. in client.navigator.URLManager#newToken the client.navigator is a package, URLManager is a class and newToken is the method name.

    One can even use #someMethod to refer to methods inside the current class without specifying the class (same for fields, ...).

    Note that in the case of inner classes there will be multiple class names: java.lang.Thread.State is an inner class in the package java.lang that's inside Thread and is named State. There's no syntax difference between inner classes and top-level classes, the only way to recognize this difference (without looking up the classes) is to see that Thread is capitalized and therefore probably a class (but Java allows lower-case classes and upper-case packages, even if conventions forbids them).