开发者

Naming convention when casually referring to methods in Java

开发者 https://www.devze.com 2022-12-25 20:27 出处:网络
Is there a Java convention to refer to methods, static and otherwise, any specific one or the whole overload, etc?

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
  • 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号