I need to make a generic class with implements cloneable
, and to accomplish this I needed to do a clone method of the class and another method to get this method.
The teacher passed it in the room, but is not working and giving Method error. What should I do?
public class Deposito <X> implements Cloneable {
public Object clone () {
Deposito ret=null;
try {
ret = new Deposito (this);
}
catch (Exception erro) {
}
return ret;
}
private X meuCloneDeX (X x) {
X ret = null;
try {
Class<?> classe = x.getClass();
Class<?>[] tipoDoParametroFormal = null;
Method metodo = classe.getMethod ("clone", tipoDoParametroFormal);
Object[] parametroReal = null;// pq clone tem 0 parametros
ret = ((X)metodo.invoke (x, parametroReal));
}
catch (NoSuchMethodException erro)
{}
catch (InvocationTargetException erro)
{}
catch (IllegalAccessException erro)
{}
return ret;
}
}
Error - cannot find symbol:
Method metodo = classe.getMethod ("clone", tipoDoParametroFormal);