Hi, I am having a problem in Generic Methods, look at this class
class ArrayAlg{
public static <T> T getMiddle(T[] a)
{
return a[a.length / 2];
}
}
The method "getMiddle" works well when i send to it a String[] as a parameter but when i send to it an int[] as a parameter it throws this exception
<T>getMiddle( T[]) in generic1.ArrayA lg cannot be applied to (int[])
incompatible types
found getMiddle
required int[]
class ArrayAlg{
public static <T> T getMiddle(T[] a)
{
return a[a.length / 2];
}
}
The method "getMiddle" works well when i send to it a String[] as a parameter but when i send to it an int[] as a parameter it throws this exception
<T>getMiddle( T[]) in generic1.ArrayA lg cannot be applied to (int[])
incompatible types
found getMiddle
required int[]
Comment