Dawno nie było klasy:Klonowanie z rodzajowych
public class Scope<C extends Cloneable & Comparable<C>> implements Comparable<Scope<C>>, Cloneable, Serializable {
private C starts;
private C ends;
...
@SuppressWarnings("unchecked")
@Override
public Object clone() {
Scope<C> scope;
try {
scope = (Scope<C>) super.clone();
scope.setStarts((C) starts.clone()); // The method clone() from the type Object is not visible
scope.setEnds((C) ends.clone()); // The method clone() from the type Object is not visible
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Clone not supported");
}
return scope;
}
}
w obiekcie mamy:
protected native Object clone() throws CloneNotSupportedException;
I Cloneable interfejs jest:
public interface Cloneable {
}
Jak należy sklonować to?
Nie bardzo rozumiem pytanie. Czy Scope nie ma już metody clone()? –
Generics nie grają w ten problem. Co jeśli 'start' i' ends' to jakiś określony typ, który zaimplementował 'Cloneable', ale nie rozszerzył dostępu do" public ". Miałbyś ten sam problem. – erickson