This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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
 
wood burning stoves
 
subject: why this error is coming if Arrays are co-variant; "cannot convert from Short[] to Integer[]"