I'm trying to do this:
Field field = classeDoObjetoDaColecao.getDeclaredField(caminho[0]);
//Here I get the setMethod, based on the attribute (via field)
Method metodoSet = classeDoObjetoDaColecao.getMethod(partesLista[0], field.getType());
metodoSet.invoke(objetoNovo,field.getType().cast(value));
Where value is a Stringand field` is a primitive int.
This generates an exception that String can't be cast to int.
Integer.parseInt(..)after figuring out that it's aStringwhich you want to convert to anint.