ImmuneEntity
Sponsor
I'm working on a java assignment, but I'm having a hell of time getting it to work. Basically, we are supposed to implement a Generic Tree class, where you can insert nodes, remove nodes, etc. So I made a GTREE (generic tree) class, and a node class...but my problem is that I want the node class to be a "generic" type, so the header is something like:
public class node<type>
That way, I can have a node that will work for any type. But no matter what version of this I try, I always run into problems. I need to be able to have a compareTo() method for this node class, so that for example I can compare Integers, strings, etc. This is necessary for the GTREE class to make comparisons. But how can I ensure that the parameterized type for the node class has a compareTo method? It won't compile unless that is the case. Is there some way to say: if(objectX has method desiredMethod) ?
Sorry if that sounds confusing. I'm just having difficulty coming up with an appropriate design for this.
public class node<type>
That way, I can have a node that will work for any type. But no matter what version of this I try, I always run into problems. I need to be able to have a compareTo() method for this node class, so that for example I can compare Integers, strings, etc. This is necessary for the GTREE class to make comparisons. But how can I ensure that the parameterized type for the node class has a compareTo method? It won't compile unless that is the case. Is there some way to say: if(objectX has method desiredMethod) ?
Sorry if that sounds confusing. I'm just having difficulty coming up with an appropriate design for this.