3
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 of inverting a scalar number, for example:
public class InversaoEscalar extends Operation{
public InversaoEscalar(Expression<Scalar> arg){
super(arg);
}
public Scalar calcular(){
return new Scalar(Parametro);
}
}
Whereas in Parametro
I’d like to pass 1/arg.calcular().getValor()
.
But I don’t understand why arg.calcular()
does not return me an object of type Scalar
, and yes of the type Expression
, since in my understanding, if I am passing a argument of the type Expression<Scalar>
, the method calcular
He should bring me a guy Scalar
, no? How to solve this problem?
se eu estou passando um arg do tipo Expression, o metodo calcular dele deveria me trazer um tipo Scalar
Why do you think that? If Arg is Expression Arg is Expression.– Math
My method of calculating() in Expression<R> returns R, so I believe that calculating in an Expression<Scalar> would return Scalar, not?
– Daniel
You in the case just have
1/arg.calcular().getValor()
at the place where it is writtenParametro
?– Math
That,
1/arg.calcular().getValor()
in place of parameter, but asarg.calcular()
is Expression, it has no methodgetValor()
. And the return is even Scalar, I edited there in the question.– Daniel