1public
   2class UnaryMinus extends UnaryExpr {
   3
   4  
   5
   6  public
   7  UnaryMinus(Expr operand) {
   8    super(operand);
   9  }
  10
  11  
  12
  13  
  14  
  15
  16  protected
  17  Object op1(Object v1) {
  18
  19    
  20
  21    if ( v1 instanceof Integer ) {
  22      return
  23        new Integer(- ((Integer)v1).intValue());
  24    }
  25
  26    
  27
  28    if ( v1 instanceof Double ) {
  29      return
  30        new Double(- ((Double)v1).doubleValue());
  31    }
  32
  33    
  34
  35    throw
  36      new IllegalArgumentException("unary - : illegal operand type");
  37  }
  38
  39  
  40
  41  public
  42  String op1ToString() {
  43    return
  44      "-";
  45  }
  46}
  47
  48
  49