Personal notes from when I was learning Java

From Nick Jenkins
Jump to: navigation, search
  • 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.