Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 5
Summary: Make copies of member variables using their clone methods if possible.
clone is a method just like any other. In a multithreaded environment you want to synchronize clone so that the underlying object stays internally consistent while being copied. You must then also synchronize the mutator
methods. Note that this is different from a constructor, which almost never needs synchronization.clone method isn't a constructor, sometimes you should treat it like one. If you do something special in each constructor, like
incrementing an "objects created" count, you probably want to do the same thing in the clone method.clone method can cause problems for clients attempting to write their own clone methods -- see the problems with Dimension in (2) above. If you're producing a third-party library, don't force your customers to work around a lack of cloning.If you're not producing a third-party library, waiting to implement clone until it's needed for each class is reasonable. This is especially true because once you've overridden clone, you must pay careful attention to overriding clone in all the child classes.
clone. However, once a class becomes cloneable, that class's children become cloneable, too. If you extend a class that is cloneable,
you must consider whether the clone method you inherit (which will make a shallow copy of all of the data in your subclass) does what you want it to. If it doesn't,
you must override clone.Because of their contracts, if you override either the equals or hashCode methods from Object, you must almost certainly override the other method as well. The complicated contracts that go with these methods make overriding
them correctly very difficult. Some of the code shipped with the standard Java libraries gets it wrong.
Here are the important contract requirements for the two methods, as documented in the javadoc documentation for java.lang.Object:
hashCode method must return the same integer value every time it is invoked on the same object during the entire execution of a Java
application or applet. It need not return the same value for different runs of an application or applet. The Java 2 platform
(Java 2) documentation further allows the hashCode value to change if the information used in the equals method changes.equals method, they must return the same value from hashCode.equals method is reflexive, which means that an object is equal to itself: x.equals(x) should return true.equals method is symmetric: If x.equals(y) returns true, then y.equals(x) should return true also.equals method is transitive: If x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.equals method is consistent. x.equals(y) should consistently return either true or false. The Java 2 javadoc clarifies that the result of x.equals(y) can change if the information used in the equals comparisons change.x.equals(null) should return false.
Object provides a simple implementation of equals. It just tests the two objects for referential equality: does x equal y? Some of the standard Java classes override this to provide a more useful notion of equality -- usually content equality
(i.e., is some or all of the data in the two objects identical?).
java.lang.Object can be found at Sun's Java Web site http://java.sun.com