3
I am implementing a B tree for a database job in Java, so that it stores any kind of objects, be generic, so I am treating as if it were Object, but in some parts of precise code methods such as compareTo(), which should be implemented, but the generic class does not provide them. What solution can I adopt?
I have the following method:
public void add (Object o){
Node aux = addRecursive (this.raiz, o);
...
}
How to force the parameter Object o have to implement the interface Comparable.
You can also use the class
java.util.Objectsif using the interfaceComparableorComparatornot feasible. This class provides utility methods for objects, see these methods here.– NinjaTroll