Invalid equality test on atomic integer [message #1773928] |
Fri, 06 October 2017 16:04 |
|
Dear all.
Consider the AtomicInteger from the Java API.
It does not define the "equals()" function, such that the following Xtend code replies always false for both functions:
def boolean fct1(AtomicInteger a, AtomicInteger b) {
a == b
}
def boolean fct2(int a, AtomicInteger b) {
a == b
}
def void main() {
var int x = 4
var AtomicInteger y = new AtomicInteger(4)
var AtomicInteger z = new AtomicInteger(4)
System.out.println(y + "==" + z + " => " + fct1(y, z))
System.out.println(x + "==" + y + " => " + fct2(x, y))
}
Indeed the generated Java code looks like:
public boolean fct1(AtomicInteger a, AtomicInteger b) {
return Objects.equal(a, b);
}
public boolean fct2(int a, AtomicInteger b) {
return Objects.equal(Integer.valueOf(a), b);
}
I have solved this issue in my own DSL by writing a specific extensions provider that is implicitly imported with my ImplicitlyImportedFeatures.
Nevertheless, I think this is an issue from all the Xbase-based DSLs.
I would like to submit a patch to the Xbase project.
If you think it is relevant, is my method the best one? Or should I explore another method ? Which one?
All the best.
Stéphane.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02215 seconds