可能重複:
operator overloading and overriding in java是否可以在Java中實現/覆蓋+和++?
我想知道是否有可能實現和覆蓋+和++運算符。
例子:
public class MyClass{
private myIncrement =0; //with its getter and setter
}
.... (another class code)
MyClass myClass = new MyClass();
myClass++;
myClass.getIncrement(); //this will return 1.
還有,如果我想創建一個Integer類,讓我在某種程度上只有三個多,當我用我++在MultipleOfThree比如,它總結三到當前實例而不是總和1.
不,這是不可能的 – 2012-07-16 17:09:12
總之,藥品出超過15個字符: – 2012-07-16 17:09:25
你就是不行號。如果你有一些空閒時間,請參閱這篇(長篇)討論;-) http://stackoverflow.com/questions/77718/why-doesnt-java-offer-operator-overloading – assylias 2012-07-16 17:09:28