| Author |
Why no implicit cast for arrays of primitives????
|
Harvinder Singh
Ranch Hand
Joined: Feb 14, 2003
Posts: 90
|
|
Hello, Can anyone tell me why compiler doesn't implicit cast arrays of primitives? Evenwhen a int can be promoted to float implicitly. Thanks.
|
Hard work beats talent<br />when talent doesn't work hard.<p> - Tim Notke
|
 |
Kashif Memon
Ranch Hand
Joined: Jul 12, 2003
Posts: 35
|
|
|
In Java Arrays are like objects and object needs explicit casting.
|
 |
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
|
|
Java does not allow an array with components of a primitive type to be cast to an array with components of a different primitive type, because the cast operation would require a change to the size of the array components. Java does allow an array with components of a reference type to be cast to an array of a different component type as long as the component types can be legally converted based on the rules of reference conversions. Those conversions don't require a change in the size of the array components, because all reference values have the same size.
|
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
|
 |
 |
|
|
subject: Why no implicit cast for arrays of primitives????
|
|
|