Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple question--  RSS feed

 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanjay Singh
Ranch Hand
Posts: 37
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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-
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!