i have a function:
public static bool Append<T>(this List<T> list, T value)
where T : IComparable<T>
{
int l = 0;
int r = list.Count() - 1;
int c = 0;
var com = 0;
while (l <= r)
{
c = (l + r) / 2;
com = list[c].CompareTo(value);
if (com > 0) r = c - 1;
else if (com < 0) l = c + 1;
else
{
list[c] = value;
return false;
}
}
if (c >= list.Count())
list.Add(value);
else
{
if (com < 0) c++;
list.Insert(c, value);
}
return true;
}
and i want to recreate it in java, but is there something equivalent to the
where T: IComparable<T>
in java?
public static <T> void append(List<T> list)
{
}
i know java have the interface java.lang.Comparable but i dont know how to implement it in a function