wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Array upcasting 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 "Array upcasting" Watch "Array upcasting" New topic
Author

Array upcasting

uzma Akbar
Ranch Hand

Joined: Sep 21, 2005
Posts: 40
int[] arr = new int[5];

long[] lrr = new long [5];

lrr = arr;


compilation error please explain. Any help is appreciated.

Uzma
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
here u defined long type array reference. It can be reassigned to any long array but cannot be reassigned to anything that is not long array.

byte arrary reference can be reassigned to another byte array
char ..............................................char array, same for all primitive types.
uzma Akbar
Ranch Hand

Joined: Sep 21, 2005
Posts: 40
Thanks Naresh

My idea was as if they are both references so smaller type may be assigned to bigger type as both are Arrays(Object) and array reference somewhat behave as an object reference. but I think that is not the case. I was just comparing it with object references as the smaller type may be assigned to bigger types.

Anyways, thanks a bunch!

uzma
vipul patel
Ranch Hand

Joined: Oct 16, 2005
Posts: 146
automatic widening or narrowing does not apply to array types as if it works for primitive types. the reason is that array types are objects.
 
 
subject: Array upcasting
 
Similar Threads
Array initilisation
Is this a correct array declaration? How?
Array declaration
here is a question and i have a very similar code but i need to convert it
How can we declare and use array as staitc if arrays are objects