1
2
3
4
5
6
7
8
9public
10class IntToDouble extends UnaryExpr {
11
12
13
14 public
15 IntToDouble(Expr operand) {
16 super(operand);
17 }
18
19
20
21
22
23
24 public
25 Object eval() {
26
27
28
29 Object value
30 = operand.eval();
31
32
33
34 if ( value instanceof Integer ) {
35 return
36 new Double( ((Integer)value).doubleValue() );
37 }
38
39
40
41 throw
42 new IllegalArgumentException("int to double: illegal operand type");
43 }
44
45
46
47 public
48 String toString() {
49 return
50 "((double)" + operand.toString() + ")";
51 }
52}
53
54
55