This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

A comment on Java style


Per Bothner wrote:
> + if (otherName.equals("java.lang.Object")

A spiffy Java idiom for getting class names is:

Object.class.getName()

Although the main reason for that is to be immune to package name changes (which would rarely apply to Object), I still prefer to never embed class names as literal strings. Also supports refactoring tools which may change class names.

Works if a static is needed too:

final static String CLASSNAME = MyClass.class.getName();

jim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]