This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, Wondering why an int array int cannot be assigned to double so if int i and double d are two arrays then d = i is not allowed. Whereas if A a and B b are arrays of objects where class B is a subclass of class A then a = b is valid. Could anyone please throw some light on this ? Thanks Satya
Satya, Your observations are right. Primitive array assignments do not undergo automatic widening conversions. Though an int can be assigned to a long, an int array cannot be assigned to a long array, even with explicit cast.Java simply cannot convert from array of one primitive type to another. The only thing you can do, however, is assigning an int array to another int array. I know it is dumb, but they call it identity conversion. Rather a complicated term for a very trivial operation!! Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Joined: Jul 18, 2000
Thanks Ajith for your input. Do you know as to why this feature was excluded. It would be great if you could give some pointers where I could get an answer. Thanks Satya
Satyashree , If you go thro RHE(page 118), it clearly states that: When oth Oldtype and Newtype are arrays, both arrays MUST CONTAIN reference type (NOT PRIMITIVES), and it must be legal to casrt an element of Oldtype to an element of Newtype.