PRE-PROPOSAL: Simple operator overloading.

Daniel Cheng j16sdiz at gmail.com
Thu Mar 26 02:25:28 PDT 2009


On Thu, Mar 26, 2009 at 5:00 PM, Vilya Harvey <vilya.harvey at gmail.com> wrote:
> You're right, I hadn't considered widening conversions. You really want
> multiple dispatch in order to solve this elegantly, but somehow I don't see
> that being added to java anytime soon. :-) So I guess that leaves two
> options (for the interface-based approach): you could throw
> ClassCastException, forcing the user to do the conversion themselves; or you
> could do something like this with generics:
>
> interface Addable<R, T> {
>    R add(T val);
> }
>
> class BigInteger implements
>    Addable<BigInteger, BigInteger>,
>    Addable<BigDecimal, BigDecimal>
> { ... }
>
> class BigDecimal implements
>    Addable<BigDecimal, BigInteger>,
>    Addable<BigDecimal, BigDecimal>
> { ... }


Interface with generic is the same interface.
  -- and you can't implement same interface twice.

I don't want to talk about generic Type Erasure, it's a PITA.

> I admit that doesn't look too elegant anymore, but I think it addresses the
> issue. Do you see any other problems there that I've overlooked?
>
> Cheers,
> Vil.
>
> Sent from my iPod
>
[...]



More information about the coin-dev mailing list