Make operator methods annotation based instead of ...
# language-proposals
e
Make operator methods annotation based instead of name based, as to allow customizable naming of methods, perhaps someone would like their
*
to call
multiply
instead of
times
, and
operator fun times(other: A) = multiply(other)
is just more boilerplate. Something like
Copy code
@Operator(TIMES)
fun multiply(other: A) {
    //...
}
would be cool :D.
d
So when compiler meets code
x * y
it should enumerate all possible names for functions, lookup for them and check that there is some function with corresponding annotation? It will take infinite time
e
Hmm, why can't methods be looked up via annotations the same way they are with names?
s
the compile checks for method signatures are much more stringent than for annotations, and that specificity is needed here. besides, it would break java interop (that apropriately-named java methods are usable as operators)
e
Ah right, that's a thing as well. Though I feel like there still should be a way to make methods which behave the same way as operator methods but aren't limited to the naming scheme of the operator methods 🤔
s
just make two methods, one calling another?
e
Boilerplate though ;-;(as mentioned in the original message, might I add)
d
You can write compiler plugin, which will generate operators for you
o
If people start to rename standard methods, they will slow down others who are trying to figure out what's going on. Kotlin could become a write-only language, and we already have these.
3