Effective Java 56 Adhere to generally accepted naming conventions
2014-04-20 10:08 小郝(Kaibo Hao) 阅读(374) 评论(0) 编辑 收藏 举报Typographical naming conventions
Identifier Type |
Type Examples |
Package |
com.google.inject, org.joda.time.format |
Class or Interface |
Timer, FutureTask, LinkedHashMap, HttpServlet |
Method or Field |
remove, ensureCapacity, getCrc |
Constant Field |
MIN_VALUE, NEGATIVE_INFINITY |
Local Variable |
i, xref, houseNumber |
Type Parameter |
T, E, K, V, X, T1, T2 |
Grammatical conventions
Identifier Type |
Type Examples |
Package |
no rules |
Class or Interface |
Timer, BufferedWriter, or ChessPiece. Collection or Comparator. Runnable, Iterable, or Accessible. BindingAnnotation, Inject, ImplementedBy, or Singleton |
Method |
append or drawImage isDigit, isProbablePrime, isEmpty, isEnabled, or hasSiblings. size, hashCode, or getTime toType(toString, toArray) asType(asList) typeValue(intValue), static factories(valueOf, of, getInstance, newInstance, getType, newType) |
Field |
initialized, composite, height, digits, or bodyStyle |
Constant Field |
MIN_VALUE, NEGATIVE_INFINITY |
Local Variable |
i, xref, houseNumber |
Type Parameter |
T, E, K, V, X, T1, T2 |
Summary
Internalize the standard naming conventions and learn to use them as second nature. The typographical conventions are straightforward and largely unambiguous; the grammatical conventions are more complex and looser. To quote from The Java Language Specification [JLS, 6.8], "These conventions should not be followed slavishly if long-held conventional usage dictates otherwise." Use common sense.
出处:http://www.cnblogs.com/haokaibo/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。