Skip to content

Make Money::with less restritive to support interop with others implementations #113

@DiegoCoronel

Description

@DiegoCoronel

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);
        }
    }

Initially I had open this issue in JavaMoney/jsr354-ri#190 and @marschall suggested to discuss it here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions