java-oo icon indicating copy to clipboard operation
java-oo copied to clipboard

Custom method names for overloaded operators

Open Shockah opened this issue 11 years ago • 2 comments

I never really made any Eclipse plugins and such, but could it be possible to use annotations to specify which method should be used as which overload? This way we could both name methods like they should be really named and still use Java-OO.

Shockah avatar Jun 27 '13 09:06 Shockah

I really like this idea of allowing the use of annotations. This means that you don't have to add extra methods with other names to the public API of your classes, which are just aliases for the methods which the user is supposed to call when not using java-oo. Don't know if it is possible or how hard it is, though...

BjarkeNL avatar May 18 '14 16:05 BjarkeNL

It is possible to implement remapping method names for operators via annotations. But it is not easy. It should be implemented in all 3 compilers (javac,eclipse,idea) separately because of different api.

How should annotations look like? For example:

@interface OperatorOverloading {
    String add() default "add";
}
@OperatorOverloading(add="plus")
class Test {
  Test plus(Test a) {...}
}

I see no major benefit from this. Another issue is you can't annotate or modify external class for operator overloading. (For example in Kotlin language it is possible via extension functions)

amelentev avatar May 27 '14 21:05 amelentev