views:

94

answers:

2

Is there a Java convention to refer to methods, static and otherwise, any specific one or the whole overload, etc?

e.g.

  • String.valueOf - referring to all overloads of static valueOf
    • String.valueOf(char) - specific overload, formal parameter name omittable?
  • String.split - looks like a static method, but actually an instance method
    • Maybe aString.split is the convention?
    • Or maybe String().split?
  • String#split - I've seen this HTML anchor form too, which I guess is javadoc-influenced

Is there an authoritative recommendation on how to clearly refer to these things?

+6  A: 

Using Class.methodName to refer to all overloads and Class.methodName(type) to refer to a specific overload is indeed the convention (as recommended by sun in this style guide for javadocs). However there is no convention to distinguish between static and non-static methods (though aString.split would make sense).

sepp2k
+1 for style guide link.
polygenelubricants
+1  A: 

Depends on the context where you'd like to refer them. I myself tend to use Javadoc-style links everywhere (in Javadocs, my blog, forum posts, etcetera) and prefer to make them clickable as well, although admittely not consistently with method arguments when used outside Javadocs (I am a bit too lazy in this, Eclipse offers autocompletion of @link tags ;) ). With regard to authoritative recommendations, there's as far as I know only the Javadoc linking recommendation.

BalusC
Can you inline an example? I think you're talking about the `String#split` form, right?
polygenelubricants
`String#split(String)` or more formally, `java.lang.String#split(java.lang.String)`. Or just shortened to `String#split()` when I use it in blogs/forums (clickable! ;) ).
BalusC
Since this is `@link`-inspired, this is most useful when referring to a specific overload, and not the whole family, right? How would you refer to the whole family of `String.valueOf` for example? (and what would the auto-linking do in this case?)
polygenelubricants
I would call it "The `String#valueOf()` methods". Inside Javadocs, you can't autolink to a group of overloaded methods. By the way: I fully agree the comment of quixoto that using the dot just feels wrong.
BalusC