public Object cast(Class aClass) {
Object casted = null;
try {
// If it goes wrong will return a new instance of the class, just to not crash DetailActivity
if (aClass.equals(GedcomTag.class))
casted = new GedcomTag(null, null, null);
else
casted = aClass.newInstance();
casted = aClass.cast(object);
} catch (Exception e) {
onBackPressed();
}
return casted;
}
Were you trying to accomplish this?
public Object cast(Class aClass) {
Object casted = null;
// If it goes wrong will return a new instance of the class, just to not crash DetailActivity
if (aClass.equals(GedcomTag.class))
casted = new GedcomTag(null, null, null);
else
casted = aClass.newInstance();
try {
casted = aClass.cast(object);
} catch (Exception e) {
onBackPressed();
}
return casted;
}
https://github.com/michelesalvador/FamilyGem/blob/master/app/src/main/java/app/familygem/DetailActivity.java#L481
Were you trying to accomplish this?