https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
e

Eric Ou

08/04/2022, 11:23 AM
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

dmitriy.novozhilov

08/04/2022, 11:25 AM
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

Eric Ou

08/04/2022, 11:26 AM
Hmm, why can't methods be looked up via annotations the same way they are with names?
s

Starr

08/04/2022, 11:29 AM
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

Eric Ou

08/04/2022, 11:33 AM
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

Starr

08/04/2022, 11:34 AM
just make two methods, one calling another?
e

Eric Ou

08/04/2022, 11:34 AM
Boilerplate though ;-;(as mentioned in the original message, might I add)
d

dmitriy.novozhilov

08/04/2022, 11:56 AM
You can write compiler plugin, which will generate operators for you
o

Oliver.O

08/04/2022, 12:11 PM
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
3 Views