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
是interface
这是由ListValueImpl
,MapValueImpl
等来实现。我想返回值是object
。代码工作正常,但我想知道这是否可以在任何方式改善?建议优化代码
public Object getValue(){return this.value; }应该工作得很好 –
“ValueItem”接口有什么意义?如果它的实现拥有像字符串和列表这样的不相关的类型,我怀疑它是它们共有的任何功能的抽象。如果它的目的只是为了调用'getValue()'并接收一个'Object',那么为什么不为变量使用'Object'而不是'ValueItem'呢? – Wyzard
感觉不好谁(如果有人)必须维护你的代码。 – mre