I have 3 classes, Expression
, Operation
, Scalar
public abstract class Expression<R extends Expression> {
public abstract R calcular();
}
public abstract class Operation<T extends Expression, R extends Expression> extends Expression {
protected T arg;
public Operation(T arg) {
this.arg = arg;
}
public T getArgumento() {
return arg;
}
}
public class Scalar extends Expression {
private double valor;
public double getValor() { }
public void setValor(double valor) { }
public Scalar(double valor) {
this.valor = valor;
}
public Scalar calcular() {
return this;
}
}
What I want is to create the class to invert a scalar number, for example:
public class InversaoEscalar extends Operation{
public InversaoEscalar(Expression<Scalar> arg){
super(arg);
}
public Scalar calcular(){
return new Scalar(Parametro);
}
}
Being in Parametro
I'd like to pass 1/arg.calcular().getValor()
.
But I do not understand why arg.calcular()
does not return an object of type Scalar
, but of type Expression
, since in my understanding, if I'm passing an argument of type Expression<Scalar>
, the method calcular
of it should bring me a type Scalar
, right? How do I solve this problem?