Érase una vez había una clase:Clonación con los genéricos
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;
}
}
En Objeto tenemos:
protected native Object clone() throws CloneNotSupportedException;
Y Cloneable interfaz es:
public interface Cloneable {
}
Cómo debería clonar ¿esta?
yo no entiendo muy bien la pregunta. ¿Ya no tiene Scope un método clone()? –
Los genéricos no juegan en este problema. ¿Qué pasa si 'start' y' ends' son un tipo específico que implementó 'Cloneable', pero no amplió la accesibilidad a" public ". Tendría el mismo problema. – erickson