java-oo
java-oo copied to clipboard
Custom method names for overloaded operators
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.
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...
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)