Effective Java 56 Adhere to generally accepted naming conventions

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.

Effective Java 56 Adhere to generally accepted naming conventions,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。