Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend 2] == != ==
[Xtend 2] == != == [message #758346] Tue, 22 November 2011 20:56 Go to next message
Edwin Park is currently offline Edwin ParkFriend
Messages: 124
Registered: July 2009
Senior Member
Hi,

I recently came across an issue when trying to implement an equals() method in Xtend 2.1. I tried doing this:

override equals(Object obj) {
    if (obj == this) return true
    if (obj instanceof MyClass == false) return false

    val that = obj as MyClass

    return this.property = that.property
}


This wound up producing an infinite loop because the == operator was interpreted as a call to ObjectExtensions.operator_equals(), which in turn calls equals().

I wanted to point this out as it caused me some confusion (hence the title of this post Smile) I also wanted to ask if this is indeed the intended behavior of == in Xtend? If so, it makes it rather inconvenient to be able to use the Java == operator from within Xtend. You have to do something like create your own extension function in a Java class, inject it as an extension, and then do something like:
if (obj.equivalentTo(this)) return true


Edwin

[Updated on: Tue, 22 November 2011 20:56]

Report message to a moderator

Re: [Xtend 2] == != == [message #758358 is a reply to message #758346] Tue, 22 November 2011 21:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it is of course intended that == is equals and not identity.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtend 2] == != == [message #758369 is a reply to message #758358] Tue, 22 November 2011 21:49 Go to previous messageGo to next message
Edwin Park is currently offline Edwin ParkFriend
Messages: 124
Registered: July 2009
Senior Member
Fair enough. Smile

As a suggestion, I think it may be useful to include an identity operator in Xtend just to make it easier for those cases when you really want to test for identity. Some other languages use === for this I believe.. or even if there were a prepackaged identicalTo() function available in Xtend this would be nice.

Thanks,
Edwin
Re: [Xtend 2] == != == [message #759211 is a reply to message #758369] Sun, 27 November 2011 17:35 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Edwin,

please file an enhancement request with a description of your use case.

Regards,
Sebastian
--
Need professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

On Tue, 22 Nov 2011 22:49:18 +0100, Edwin Park
<forums-noreply@eclipse.org> wrote:

> Fair enough. :)
>
> As a suggestion, I think it may be useful to include an identity
> operator in Xtend just to make it easier for those cases when you really
> want to test for identity. Some other languages use === for this I
> believe.. or even if there were a prepackaged identicalTo() function
> available in Xtend this would be nice.
>
> Thanks,
> Edwin
>
Previous Topic:Duplicate JvmAnnotationTarget '&lt;unnamed&gt;' when using a AbstractModelInferrer
Next Topic:Exceptions when opening linked resource
Goto Forum:
  


Current Time: Thu Apr 25 14:59:37 GMT 2024

Powered by FUDForum. Page generated in 0.03136 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top