This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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


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
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: why this error is coming if Arrays are co-variant; "cannot convert from Short[] to Integer[]"
 
It's not a secret anymore!