I am trying to make a generic method to compare objects from many types.
This is my simple interface
interface comparable<T> {
boolean isBiggerThan(T t1);
}
and this is one implementation for it:
class StringComparable implements comparable<String> {
public StringComparable(String s) {
this.s = s;
}
String s;
@Override
public boolean isBiggerThan(String t1) {
return s.equals(t1);
}
}
this is my class that has a generic method:
class Utilt {
public static <T extends comparable<T>> int biggerThan(T values[], T t) {
int count = 0;
for (T oneValue : values) {
if (oneValue.isBiggerThan(t)) {
count++;
}
}
return count;
}
}
I call that method like this:
public class TestTest {
public static void main(String args[]) {
StringComparable a = new StringComparable("Totti");
StringComparable pi = new StringComparable("Pirlo");
int i = Utilt.biggerThan(new StringComparable[] { a, pi }, a);
}
}
But I get this error:
The method `biggerThan(T[], T)` in the type `Utilt` is not applicable for the arguments `(StringComparable[], StringComparable)`