skip to main |
skip to sidebar
Language Lessons
Java Tech columnist Jeff Friesen has been coding in Java for nearly ten years, and in that time, he's found some surprises in the language, like how += doesn't necessarily do what you expect, or the hazards of invoking a potentially overridden method in a constructor. In this article, he provides some important lessons based on this experience.
summary:- Do not use the string concatenation operator in
lengthy loops or other places where performance could suffer. - Do not call overridable methods from superclass
constructors. - Do not use assertions to validate method
arguments. Use if
statements that explicitly throw
exceptions if those arguments aren't valid. - Use interfaces for flexibility. Use abstract
classes for ease of evolution or to capture the essence of rigid
class hierarchies while avoiding the creation of objects that mean
nothing. - Use covariant return types to minimize upcasting
and downcasting. - Don't forget the superclass while writing a
subclass. - Remember that compound assignment operators
automatically include cast operations in their behaviors.
rating comment: Articles like this on are always useful, cause you can never know enough of these little mysteries!
No comments:
Post a Comment