public class TestGenericAccumulator
{
static class AddableInt implements Addable<AddableInt> {
private int value;
public AddableInt( int initialValue ) {
this.value = initialValue;
}
public AddableInt add(AddableInt addableInt) {
return new AddableInt(this.value + addableInt.value);
}
public int getValue() {
return value;
}
public String toString() {
return Integer.toString(value);
}
}
public static void main(String[] args)
{
System.out.println("Testing generic accumulators");
GenericAccumulator<AddableInt> acc =
new GenericAccumulator<AddableInt>( new AddableInt(1000) );
acc.incrementBy( new AddableInt(3) );
acc.incrementBy( new AddableInt(501) );
acc.incrementBy( new AddableInt(500) );
System.out.println(acc.getValue());
}
}
|