Method problem
I have 2 similar classes called
Number(integers) and Real(doubles)
I have another class called Arithmetic in which there are arithmetic functions like "plus,minus,division,multiplication"
In the Arithmetic class i have this method of addition, where if the numbers are taken and if they are integers it returns an integer value or if they are doubles, it returns real:
public Number plus(Environment env)throws LispException{
if (this.isNull() && this.numberP())returnnew Number(0);
if (this.isNull() && this.realP())returnnew Real(0);
SExpression carResult = this.car().eval(env);
if (carResult.numberP() )
{
returnnew Number(((Number)carResult).intValue() + this.cdr().plus(env).intValue());
}
elseif (carResult.realP() )
{
returnnew Real(((Real)carResult).realValue() + this.cdr().plus(env).realValue());
}
}
My problem is that when i call this method by
"public Number plus(Environment env) "
in line 3 it gives me incompatible type of "Real" because it expects a "Number", This occurs wherever i have Real types inside this method.
Is there a way to solve this problem? i was thinking of casting, but how would i do that..
Thanks

