首页 > 编程语言 > 详细

Effective Java 56 Adhere to generally accepted naming conventions

时间:2014-04-20 23:39:26      阅读:600      评论:0      收藏: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.

Effective Java 56 Adhere to generally accepted naming conventions,布布扣,bubuko.com

Effective Java 56 Adhere to generally accepted naming conventions

原文:http://www.cnblogs.com/haokaibo/p/adhere-to-generally-accepted-naming-conventions.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!