source: RiceX COMP 322 Fundamentals of Parallel Programming
public
class
MutableInt
extends
Number
implements
Comparable<MutableInt>,
Mutable<Number> {
/** The mutable value. */
private
int
value;
/**
* Constructs a
new MutableInt with the default value of zero.
*/
public MutableInt() {
super();
}
/**
* Adds a value to
the value of this instance.
*
@param operand
the value to add, not null
*/
public
void
add(final
int
operand)
{
this.value +=
operand;
}
/**
* Returns the
value of this MutableInt as an int.
*
@return the numeric value represented by
this object after conversion to type int.
*/
@Override
public
int
intValue() {
return
value;
}
}
MutableInt
total
=
new
MutableInt();
finish(()
-> {
async(() -> {
total.add(11);
});
total.add(10);
});
System.out.println(total.intValue());