Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "#" in MyType#myMethod() and the difference with "." as in MyType.myMethod()

Well, all is in the title...

I understand that both forms refer to the method, but I don't see what # adds to the other form.

like image 569
mins Avatar asked Dec 11 '22 05:12

mins


1 Answers

The hash character (#) is not part of the Java language.

It has a special use in javadoc. The specification states

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 (#).

and

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.

The notation doesn't only apply to methods, it applies to any type member. It helps remove ambiguity from fully qualified type names.

like image 200
Sotirios Delimanolis Avatar answered Jan 25 '23 23:01

Sotirios Delimanolis