Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I pass arrays like this in Java

Tags:

java

arrays

I have a function:

draw(int[] a)
{
   //...
}

and I want to pass in the array {3,4,5}. Why can't I call:

draw({3,4,5});
like image 679
Mike Avatar asked Feb 10 '12 05:02

Mike


1 Answers

The type of {3,4,5} is ambiguous (could be int[], short[], long[], etc..). Try:

draw(new int[]{3,4,5});
like image 73
calebds Avatar answered Sep 27 '22 19:09

calebds