Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload === for equals() #44

Open
cchudant opened this issue Feb 14, 2017 · 4 comments
Open

Overload === for equals() #44

cchudant opened this issue Feb 14, 2017 · 4 comments

Comments

@cchudant
Copy link

Can you overload a new operator === for equals() ?
I mean:
var1.equals(var2) -> var1 === var2
That world be great if that can be done!

@ghost
Copy link

ghost commented Feb 21, 2017

just doing that is going to hurt if var1 is null, but it should also evaluate to true if both are null, so

(var1==var2 || (var1!=null && var1.equals(var2)))

@elect86
Copy link

elect86 commented Feb 22, 2017

If I may, I tried java-oo once looking for operator overloading... but when I discovere Kotlin, it was another different world...

I just accept that java is what it is.. and I spent so much time in workarounds for its limitations that I regret I didn't try earlier to look around for alternatives..

Give a try to Kotlin (100% java compatible), you won't regret
(Sorry for the ot!)

my 2 cents

@amelentev
Copy link
Owner

=== is a new lexeme for a Java Parser. But java-oo works only after parsing stage (yet), so adding completely new syntactic constructs will require much work.
I don't have time for this, but I'm open to contributions.
Probably it is possible to modify javac parser via javac 8 Plugin API[1]. But Eclipse and IntelliJ will require major hacks.
[1]: https://docs.oracle.com/javase/8/docs/jdk/api/javac/tree/com/sun/source/util/Plugin.html

@Maaartinus
Copy link

Could something like ~== work? It's two legal tokens ~ and == in an illegal arrangement. It resembles ≅ (APPROXIMATELY EQUAL TO, U+2245), which is semantically fine as equals is a weaker relation than ==.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants