问题
I have the following class
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...
The method testing(Integer[]) in the type TestAlgorithm is not applicable for the arguments (int[]) app.java /TestApp/src/Application line 10 Java Problem
回答1:
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};
来源:https://stackoverflow.com/questions/31684444/passing-integer-array-to-method-that-uses-a-generic-array-of-elements