I'm trying to make the following function which counts the number of distinct elements in any array:
public static long distinctElements(T[] ar)
{
return Arrays.asList(ar).stream().distinct().count();
}
The problem here is that I cannot use 'T[] ar' as a parameter (Java says it doesn't know the type T). How can I fix this? This function is in a utility class which does not incorporate the type T (like ArrayList and TreeSet do).