wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Simple question-- Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Simple question--" Watch "Simple question--" New topic
Author

Simple question--

Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Hi,

why its not possible to assign byte array to int array while in the case of objects its possible.

int[] arrNew;
byte[] arrByte={1,2,3};
int[] arrInt={1,2,3};

arrNew=arrByte; /// not allowed

Regards,

Abdul Mohsin


Regards, Abdul Mohsin
Sanjay Singh
Ranch Hand

Joined: Mar 02, 2006
Posts: 37

why its not possible to assign byte array to int array while in the case of objects its possible.


Reason: The Array of primitive can't be cast to an array of a different primitive type. While in the case of object it is possible cause array itself is Object, so we can assign an array to Object. e.g.

this code is fine-


Regards, Sanjay Singh
SCJP-1.6, OCEWCD 6
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Simple question--
 
Similar Threads
aggregate initialization
HI please Help with. GC Kathy and Bert Book
Anonymous Array
Array declaration and initialization
Question on Multidimensional Array