Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtend 2] == != ==
[Xtend 2] == != == [message #758346] Tue, 22 November 2011 15:56 Go to next message
Eclipse UserFriend
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 15:56] by Moderator

Re: [Xtend 2] == != == [message #758358 is a reply to message #758346] Tue, 22 November 2011 16:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian
Re: [Xtend 2] == != == [message #758369 is a reply to message #758358] Tue, 22 November 2011 16:49 Go to previous messageGo to next message
Eclipse UserFriend
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 12:35 Go to previous message
Eclipse UserFriend
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: Sun Jul 27 05:02:21 EDT 2025

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

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

Back to the top