aspose file tools*
The moose likes Java in General and the fly likes why this error is coming if Arrays are co-variant; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "why this error is coming if Arrays are co-variant; "cannot convert from Short[] to Integer[]"" Watch "why this error is coming if Arrays are co-variant; "cannot convert from Short[] to Integer[]"" New topic
Author

why this error is coming if Arrays are co-variant; "cannot convert from Short[] to Integer[]"

Abhineet Kapil
Ranch Hand

Joined: Feb 08, 2010
Posts: 52

Arrays are co-variant and Collections are invariant.

I am try to assign an array of java.lang.Short to an array of java.lang.Integer.
But I am getting a compile time error.

Type mismatch: cannot convert from Short[] to Integer[]

Can someone please explain why this error is coming if Arrays are co-variant.


Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

because, Short is not an Integer. try this
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why this error is coming if Arrays are co-variant; "cannot convert from Short[] to Integer[]"