「java」hashCode()、clone()とfinalize()のメモ

サンプルコード
// hashcodeメソッド
private volatile int hashCode = 0;
public int hashCode() {
if (hashCode == 0) {
int result = 17;
result = 37 * result + areaCode;
}
return hashCode;
}

// Cloneメソッド
public class Clone1 implements Cloneable {
public Object clone() {
return super.clone();
}
}

// Finalizeメソッド
Object f = new Object() {
public void finalize() {
System.out.println(“Running finalize()");
}
};
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println(“Running Shutdown Hook");
}
});

Java

Posted by arkgame