Код: Выделить всё
public class SimpleHashtable implements Cloneable {
private Entry[] buckets;
private int size;
private static class Entry {
final K key;
V value;
Entry next;
Entry(K key, V value, Entry next) {
this.key = key;
this.value = value;
this.next = next;
}
// Recursively clone the linked list of entries
Entry deepCopy() {
return new Entry(key, value, next == null ? null : next.deepCopy());
}
}
public SimpleHashtable() {
buckets = new Entry[16]; // Default size
}
@Override
public SimpleHashtable clone() {
try {
@SuppressWarnings("unchecked")
SimpleHashtable result = (SimpleHashtable) super.clone();
result.buckets = new Entry[buckets.length];
for (int i = 0; i < buckets.length; i++) {
result.buckets[i] = buckets[i] != null ? buckets[i].deepCopy() : null;
}
return result;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}
Я что-то упустил или пример неверный?
Подробнее здесь: https://stackoverflow.com/questions/784 ... allow-copy