Reputation: 1
I'm trying to sort some arrays in Java using this line:
a = sortFacade.sort(2, false, a);
where 'a' is an already initialised int array. When I try to compile it, I'm told that the 2 is a long, not an int. I've tried casting it with (int)2 with no luck.
I also tried the line
sortFacade.sort(2, false, a);
and the code compiles.
does anyone know a fix to this?
Edit: Here's the message I get in Terminal:
Experimenter.java:146: incompatible types
found : long
required: int[]
a = sortFacade.sort(2, false, a);
^
This line is found in code like this:
public static void Experiment1()
{
for(int size = 5000; size <= 100000; size = size + 5000)
{
int[] a randomArray(size, 1000); //a random array of size 'size' and values from 1 - 1000
a = sortFacade.sort(2, false, a);
/** This is where the error occurs. 2 specifies insertion sort (error occurs
with other acceptable numbers here as well,false specifies descending
order, 'a' specifies the array to be sorted.*/
}
}
The SortFacade is a facade that interacts with all my different sorting algorithms. 2 is an acceptable value and calls to the same method (with different parameters) do work in other parts of the code.
Upvotes: 0
Views: 2112
Reputation: 10290
This basically talks for itself.
Experimenter.java:146: incompatible types
found : long
required: int[]
You said yourself that the variable a
is an array of integers. The above error tells you that although the method returns a long
, you require it to return an array of integers int[]
, because you try to assign that long
value to a
.
Upvotes: 1
Reputation: 7848
if a
is an int[]
array, then it would seem that the error you are receiving is because sortFacade.sort
has a return type of long
and you are trying to assign it to the a
array - which is illegal.
The reason sortFacade.sort(2, false, a);
compiles is because you are not assigning it to anything. If you said: long b = sortFacade.sort(2, false, a);
it should compile and work.
Upvotes: 0