Please can you tell me if it is possible to overload operators in Java? If it is used anywhere in Java could you please tell me about it.
Just use Xtend along with your Java code. It supports Operator Overloading:
package com.example;
@SuppressWarnings("all")
public class Test {
protected int wrapped;
public Test(final int value) {
this.wrapped = value;
}
public int operator_plus(final Test e2) {
return (this.wrapped + e2.wrapped);
}
}
package com.example
class Test2 {
new() {
val t1 = new Test(3)
val t2 = new Test(5)
val t3 = t1 + t2
}
}
On the official website, there is a list of the methods to implement for each operator !