What is wrong with the following?
I am just trying to make a simple generic method so that I can do Min(1,2) and have it return the smaller of the two values (in this case 1). When compiling, I get this:public static <T> T Min(final T Value1, final T Value2) { return((Value1 < Value2) ? Value1 : Value2); }
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The operator < is undefined for the argument type(s) T, T
How do I best do this?
I know in C using templates I can simply do:
How do I do this in Java? All the examples I see use "Collections", but I don't. I just want to use simple Integers.template <typename T> T Min(const T &Value1, const T &Value2) { return((Value1 < Value2) ? Value1 : Value2); }