amelentev / java-oo

Java Operator Overloading
http://amelentev.github.io/java-oo/
268 stars 31 forks source link

[request] Equality operator override #22

Open ghost opened 10 years ago

ghost commented 10 years ago

This is a great project, thank you for making this.

The only thing it's lacking is overloading of == operator. Comparing Strings can be a pain in the ass without it.

I know this might break things, as == should compare references and everyone is used to that, but maybe some workaround could be made.

We don't have to override == for every class and object. Could it be enabled only for some classes that we explicitly choose? (it would have it's limitations, but it's better than nothing)

Or maybe is there a possibility to add a new operator? Like ===, which would convert a===b into something like (a == null ? b==null : a.equals(b))

amelentev commented 10 years ago

Yes, It is possible to implement overriding == only for specified classes. I will try to implement it when I have time.

Adding new operators is very complicated. To do it we need to extend Java parser but oo-plugin only works after parsing (in annotation processing stage). There are no extension points before annotation processing in Java7 compiler. But there is some support of plugins in Java8 compiler (-Xplugin). Maybe it is possible to extend parser there. More research needed.