public Object getValue() { ValueItem valueItem = null; Object returnValue = null; if(this.value instanceof StringValueImpl) { valueItem = (StringValueImpl) this.value; } else if(this.value instanceof ListValueImpl) { valueItem = (ListValueImpl) this.value; } else if(this.value instanceof MapValueImpl) { valueItem = (MapValueImpl) this.value; } if(valueItem!=null) returnValue = valueItem.getValue(); return returnValue; } ValueItem is an interface which is implemented by ListValueImpl, MapValueImpl etc .. I want return value which is an object. The code works fine but i was wondering if this can be improved in any way ?
ValueIteminterface? If its implementations hold unrelated types like strings and lists, I doubt it's an abstraction of any functionality they have in common. If its purpose is just that you can callgetValue()on it and receive anObject, why not just useObjectinstead ofValueItemfor your variables?ValueItemthanStringValueImpl,ListValueImplandMapValueImpl?Propertyinterface is nowValueItem.