I had a situation where I needed to implement my own MonetaryAmount (decorated Money) and now Im not able to integrate my code smooth with Money::with because theres a forced cast to Money. Is it possible to relax this and return a MonetaryAmount ?
@Override
public Money with(MonetaryOperator operator) { // <-- Can you return MonetaryAmount ?
Objects.requireNonNull(operator);
try {
return Money.class.cast(operator.apply(this)); // <-- Can you relax this code ?
} catch (MonetaryException e) {
throw e;
} catch (Exception e) {
throw new MonetaryException("Operator failed: " + operator, e);
}
}
I had a situation where I needed to implement my own MonetaryAmount (decorated Money) and now Im not able to integrate my code smooth with Money::with because theres a forced cast to Money. Is it possible to relax this and return a MonetaryAmount ?
Initially I had open this issue in https://github.com/JavaMoney/jsr354-ri/issues/190 and @marschall suggested to discuss it here.