I have a Value Class and there is an Object value in it. I want to use the value as String, Integer or Double.
The asDouble method controls instanceof value object. If it is not Double or Integer returns 0.
Generally it works but sometimes although it is Double returns 0;. I couldn't the reason of it.
When I debug I can see:
Here is my Value class
public class Value{
public Object value;
public Value(Object value) {
this.value = value;
}
public Double asDouble() {
if (this.value instanceof Integer || this.value instanceof Double) {
return Double.parseDouble(String.valueOf(this.value));
} else {
return 0.0;
}
}
}
Could anybody explain where did I go wrong

Doublesomewhere that isn'tjava.lang.Doubleor you've got multithreaded code modifyingvaluewhile you read it.Doubletovalue, but did enter a different object. Like aStringmaybe"0.2"instead of just0.2.Valueobjects inside each other, only the inner one containing aDouble. Sothis.valueis aValue, not aDouble, so theelsepart is executed.Numberthen call.doubleValue()to get the value as a double.Valueinstance inside anotherValueindeed seems to be what's shown in the hover.