本文介绍了将整数数组传递给使用通用元素数组的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下课程
public class TestAlgorithm<E extends Comparable<? super E>>
{
public void testing(E[] array)
{
for(int i = 0; i<= array.length; i++)
{
... // processing code (not important here)
}
}
}
在我的主要应用程序类中,我有这个...
in my main application class class I have this...
public static void main(String[] args)
{
int [] test = {3,7,8,5,2,1,9,5,4};
TestAlgorithm<Integer> myAlgo = new TestAlgorithm<Integer>();
myAlgo.testing(test);
}
对我来说-看起来很有意义-但是在尝试运行它时出现以下错误...
Which to me - looks like it makes sense - but I get the following error when I try to run it...
推荐答案
您将 myAlgo
定义为 Integer
类型,但是您正在调用 int
.使用 Integer
向量:
You defined myAlgo
as Integer
type, but you are calling a vector of int
. Use an Integer
vector:
Integer[] test = {3,7,8,5,2,1,9,5,4};
这篇关于将整数数组传递给使用通用元素数组的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!