I would like to create a template function that relies on the universal type of support ++and --. As we know, Java does not support operator overload support, so apparently I need to define an interface for which functions are required increment()and decrement():
public interface Quantized<E> extends Comparable<E> {
public <E extends Quantized> E increment();
public <E extends Quantized> E decrement();
}
public class Sequencer<E extends Quantized>{
private E value;
public <E extends Quantized> E doSometingWithSequence(){
...
E rv = value.increment();
return rv;
}
}
If I want a template to support any class, then even knowing the interface, which says it is supported ++and --not enough, because Java does not allow us to implement operators for classes. However, it would be nice to let the template function support types such as Integer, without the need for a wrapper class for an interface Quantized.
( )?