Are there interfaces associated with overloadable operators? E.g. a `Plus` for the `plus()` method. ...
m
Are there interfaces associated with overloadable operators? E.g. a
Plus
for the
plus()
method. It would be great to be able to define
sum()
on an
Iterable<Plus>
, for instance.
a
no
n
There is no such thing, as far as I know. Of course, you could make it yourself and define an extension method for
Iterable<Plus>
, but it wouldn't support types you don't create yourself. There is a proposal right now to add the ability to extend existing classes, which would allow what you're looking for
a
easiest way to do that is using ad-hoc polymorphism http://beust.com/weblog/2016/06/20/ad-hoc-polymorphism-in-kotlin/
m
I’ll take a look, thanks. I’m spoiled by Rust…
n
a
@mp sadly the java-interop made things abit harder as they should be
m
Understandable