Im using the following code that the fieldValue can have simple property , there is a way to check before im doing this code if fieldValue is not contain object that cannot be cast to string ?to avoid dump
keyVal.put(fieldName, (String) fieldValue);
Im using the following code that the fieldValue can have simple property , there is a way to check before im doing this code if fieldValue is not contain object that cannot be cast to string ?to avoid dump
keyVal.put(fieldName, (String) fieldValue);
if (fieldValue instanceof String)
Since String is a final class (and hence cannot have subclasses), I would consider using getClass over instanceof:
if (fieldValue != null && fieldValue.getClass() == String.class)
if (fieldValue instanceof String) {
keyVal.put(fieldName, (String) fieldValue);
}