3

What is the proper way to write a fully qualified reference to a method name in Java?

  1. Message[] com.sun.mail.imap.IMAPFolder#addMessages(Message[])
  2. Message[] com.sun.mail.imap.IMAPFolder.addMessages(Message[])
  3. Some other way
Makoto
  • 104,088
  • 27
  • 192
  • 230
Robottinosino
  • 10,384
  • 17
  • 59
  • 97
  • 2
    with what purpose? JNDI? – ricardoespsanto Aug 02 '12 at 13:06
  • Also, but not just. Isn't it there an official way to write references? I can't certainly use "any" character "anywhere", like com$sun%mail^... Somewhere I find "#" used to separate Class and Method names, somewhere else I find ".", it's confusing. Why the downvotes? – Robottinosino Aug 02 '12 at 13:13
  • Allow me to add that my use of JNDI is through Commons Configuration, using a "JNDIConfiguration" object where keys should be FQ method names. This is not the only case, as I said above. – Robottinosino Aug 02 '12 at 21:23

2 Answers2

2

If the signature of the method is Message[] addMessages(Message[] msgs)...

...and the class name is IMAPFolder...

...and it's in the package com.sun.map.imap...

...then the fully qualified method name would be com.sun.map.imap.IMAPFolder.addMessages(Message[] msgs).

Visible class/instance variables share the same pattern, although for the sake of OO design, this is typically discouraged.

Normally, one only concerns themselves with the fully qualified object name, not the method/[instance|class] variable name.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • 1
    Could you please add to your answer the source of this recommendation that makes it more or less "official"? – Robottinosino Aug 02 '12 at 13:48
  • In terms of the FQCN, you can find the wiki link [here](http://en.wikipedia.org/wiki/Fully_qualified_name). In terms of the OO recommendation, this is what I've seen and encountered; encapsulation is broken if you're using public variable names instead of accessors (and don't get me started on static variables). – Makoto Aug 02 '12 at 14:32
  • Actually, the JavaDoc uses # instead of . – Robottinosino Aug 15 '12 at 20:12
  • @Robottinosino: You sure you're not getting it mixed up with anchor links generated by Javadoc? I've not seen that notation used explicitly in Java before, maybe Ruby. – Makoto Aug 15 '12 at 20:15