PRE-PROPOSAL: Simple operator overloading.

rssh at gradsoft.com.ua rssh at gradsoft.com.ua
Thu Mar 26 03:02:52 PDT 2009


>>
>> 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>
>> { ... }
>>
>> 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?
>>
>
>  Yes, this can work.
>

Ohh, we need relief generics for this.
Now see:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#FAQ104


>> Cheers,
>> Vil.
>>
>> Sent from my iPod
>>
>> On 26 Mar 2009, at 01:08, Daniel Cheng <j16sdiz at gmail.com> wrote:
>>
>>> On Wed, Mar 25, 2009 at 8:03 PM, Vilya Harvey
>>> <vilya.harvey at gmail.com> wrote:
>>>> I would love to see this, but I'd prefer it to be based on special
>>>> interfaces rather than annotations. This would adhere to the
>>>> principle, mentioned on this list a few times, that annotations
>>>> shouldn't modify the results of the compiler.
>>>>
>>>> For example, if you implement the Addable (say) interface then your
>>>> class can be used the '+' operator; or the Subtractable interface for
>>>
>>> We can't specify the return type if we use an interface.
>>>
>>> We may want to do something like this:
>>>
>>>        BigInteger + BigInteger     = BigInteger
>>>        BigInteger + BigDecimal   = BigDecimal
>>>        BigDecimal + BigInteger   = BigDecimal
>>>        BigDecimal + BigDecimal = BigDecimal
>>>
>>> There is no way to implement this using interface.
>>>
>>>> the '-' operator. I'd imagine you would also want some grouping
>>>> interfaces, to reduce the number of interface declarations required
>>>> when overloading multiple operators (e.g. interface Artihmetic
>>>> extends
>>>> Addable, Subtractable etc.).
>>>>
>>>> Whatever form it takes though, it would be great to have this
>>>> capability in Java!
>>>>
>>>> Vil.
>>>>
>>>>
>>>> 2009/3/25  <rssh at gradsoft.com.ua>:
>>>>> Permanent URL: http://docs.google.com/Doc?id=dhhvggr8_18djp85shk
>>>>>
>>>>> Probably too big, but anyway.
>>>>>
>>>>> As I remember, alternative proposal (made [] and []= syntax sugar on
>>>>> well-known interfaces, as with for-each loop) still not submitted.
>>>>> If
>>>>> anybody want submit such proposal, then it is possible to reuse
>>>>> JLS-changed for 15.26.1 from there.
>>>>>
>>>>>
>>>>
>>>>
>>
>
>
>





More information about the coin-dev mailing list