How to handle comparison operator for Generic Java class accepting String or Integer
问题 I am interested in using a generic Java class which can handle String or Integer data type. I'd like to utilize the comparison operator, but it appears to have a compile error: Operator < cannot be used on generic T How can I achieve using comparison operators such as <, >, =, etc. for T ? (Assuming T is Number or String ). public class Node<T> { public T value; public Node(){ } public void testCompare(T anotherValue) { if(value == anotherValue) System.out.println("equal"); else if(value <