I have seen some nice Java compiler hacks wherein you can replace assertions by throw-exception statements, you can have auto-generated properties for fields and so on...
I was just wondering...
Is it possible to hack Java compiler so that it supports Operator Overloading?
EDIT :
It's not that I am missing operator overloading in Java or something. I just want to know whether it is possible to implement it using the hacks mentioned in the links I have given above. So please do not suggest me to switch to some other language like Scala (which I am already learning anyway! :D ).
EDIT :
Please just tell me whether it is possible to do it using JSR 269 or something like that. :|
Thanks.
In response to the edited question, the only way you can implement true operator overloading in Java is to add it to the language. This means that you either have to change the compiler to compile your code or write a preprocessor that converts your code to standard Java. For the former, you can download a nearly complete FOSS java implementation from either GNU or the OpenJDK project. For the latter, you can either write your own parser using things like JavaCC etc. (examples are on this page) or you can use JFront as a base to add your own syntax.
It is possible to implement Java operator overloading using JSR 269 with some hacks. Look at java-oo plugins for javac and Eclipse JDT:
http://amelentev.github.com/java-oo/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With