Difference between revisions of "Personal notes from when I was learning Java"

From Nick Jenkins
Jump to: navigation, search
 
Line 1: Line 1:
 +
taricric
 
* All objects point to the same thing, so be sure to use Object.clone() when you do not want to modify the original object.
 
* All objects point to the same thing, so be sure to use Object.clone() when you do not want to modify the original object.
 
* The "clone()" interface sucks for custom objects. Use a custom "duplicate()" function instead, which cannot throw an exception.
 
* The "clone()" interface sucks for custom objects. Use a custom "duplicate()" function instead, which cannot throw an exception.

Revision as of 15:38, 9 November 2007

taricric

  • All objects point to the same thing, so be sure to use Object.clone() when you do not want to modify the original object.
  • The "clone()" interface sucks for custom objects. Use a custom "duplicate()" function instead, which cannot throw an exception.
  • Casting is a pain (feels very verbose if you are used to loosely-typed languages)
  • The operator "+" is undefined for class Integer. That's right, kids, this is invalid syntax:
        Integer i = new Integer(5);
        i = i + 2;
An integer that you cannot add to with the 'plus' operator. Useful, huh?
  • You need hashCode and equals methods for all sorts of things, and if you don't implement these you'll get unexpected bugs. As such, a static analysis tool (like "findbugs") is absolutely essential.