Java doesn't support operator overloading , so when I want to plus_equals [ += ] two objects like this :
// pseudo : a += b ;
In Java I have to write :
a . set ( a . add ( b ) ) ;
Which can be wrapped in a method to more closely mimic the syntax of the "+=" operator to get :
a . add_equals ( b ) ;
When I try to do the same for class member variables like this :
// pseudo : a.x += a.x ;
a . setX ( add ( a.getX() , b.getX() ) ) ;
I encounter a problem - the getters and setters get in the way . I either have to directly access the augend ( a.x ) of the addition which means I have to make it public ...
a . getX ( ) . add_equals ( b . getX() ) ;
or I have to make a kinda confusing looking mutator method
a . setX_add_equals ( b.getX() ) ;
Is there an elegant solution to this problem that both :
( 1 ) - Doesn't interfere with the access modifiers of the member variables .
( 2 ) - Is intuitive in terms of readability .
In advance , thanks for your time .