[Xtend 2] == != == [message #758346] |
Tue, 22 November 2011 20:56 |
Edwin Park 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 ) 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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03249 seconds