I am trying to implement an algorithm that needs to compare some elements based on an ordering defined by an (any given) enum type, so I am trying to specialize it using enums in template definition. I tried with simple code to see if my idea would work, but I couldn't make it compile. Any ideas on how to approach the problem. Here is my code:
public class Algorithm <T extends Enum<T> >{
public TLCAlgorithm(){
T t1;
T t2;
if (t1<t2){
//do something
}
}
Essentially t1
and t2
will be different values of that enum type defined somewhere else. I am planning to have different enum types defining different kinds of orderings, so that by instantiating the class with a different enum type, the algorithm should behave differently. I would be instantiating as this: Algorithm<Ordering1> alg1=new Algorithm<Ordering1>()
.