以下はコードスニペットです。
public class Operand<T> {
private OperandStore store;
private final int operandType, operandId;
public Operand( int operandType, int operandId, OperandStore store ) {
this.operandId = operandId;
this.operandType = operandType;
this.store = store;
}
@SuppressWarnings( "unchecked" )
public T evaluate() {
try {
return ( T ) store.getValue( operandType, operandId );
}
catch ( Exception e ) {
return null;
}
}
}
私のgetValue
方法:
public Object getValue(int operandType, int operandId ) {
// return some value from a <String, Object> hashmap based on some condition
}
上記のクラスのオブジェクトを作成すると、次のようになります。
Operand<Integer> obj = new Operand<>(1,1,store);
store.getValue( operandType, operandId )
...そしてそれが文字列を返すことを確認してくださいtry
。ブロックで発生していないエラーが発生することを期待しています。string
代わりに値を返しています。
何らかの理由?親切に説明してください。ありがとう。