【发布时间】:2015-11-19 08:01:19
【问题描述】:
我在初始化数组并返回它时遇到了问题。该方法假设返回通用数组的常见项,但我无法初始化数组“a”或返回它。有什么建议吗??
public static <T> T[] commonItems( T[] arr1, T[] arr2)
{
T[] a;
int pos = 0;
for( int i = 0; i < arr1.length; i++)
{
for(int j = 0; j < arr2.length; j++)
{
if(arr1[i].equals(arr2[j]))
{
a[pos] = arr1[i];
pos++;
}
}
}
return a;
}
【问题讨论】:
-
你可能需要传递类类型:stackoverflow.com/questions/529085/…
-
看看这里也许这会有所帮助stackoverflow.com/questions/529085/…
-
谢谢你帮了我很多