I have a problem with invoking String.valueOf method. As argument I passed generic method which returns Integer type. And then exception is thrown because program try to cast that returned Integer to char[] to invoke String.valueOf method. As I know String has overloaded valueOf() method and one of them can take Integer parameter.
Below is screenshot from Eclipse expression evaluation which shows situation.
This line throws ClassCastException
String quality = String.valueOf(model.get(property));
This is what model.get(property) invokes:
public <X> X get(String property) {
X value = null;
try {
if (allowNestedValues && NestedModelUtil.isNestedProperty(property)) {
return (X) NestedModelUtil.getNestedValue(this, property);
}
if (map != null) {
Object objValue = map.get(property);
if (objValue != null)
value = (X) objValue;
}
} catch (Exception e) {
}
return map == null ? null : value;
}
EDIT:
I added this condition and compiler goes inside the if statement
if(model.get(property) instanceof Integer)
{
quality = String.valueOf(model.get(property));
}


String.valueOfvariant to use?valueOfhas overloads forObject,char[]and various primitive types.char[]is the "most specific" one and is therefore chosen (presumably).