SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
i don't understand how 2 dimensional array is converted to 1 dimensional
SCJP2. Please Indent your code using UBB Code
Originally posted by William Brogden:
Since a is a 2d array, you are casting an array of a[] - each item in obj contains an array of int, not an int.
Bill
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
SCJP2. Please Indent your code using UBB Code
i don't understand how 2 dimensional array is converted to 1 dimensional
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Originally posted by Jose Botella:
Veena,
i.clone() returns an object of runtime type int[], whose compile type is Object. A compile type Object can be casted to Object[]. But as you said it fails at runtime.
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Originally posted by Roger Chung-Wee:
It may be worth knowing what primitive array references can be converted to. A primitive array has no hierarchy, except that it inherits from Object and that it implements the Cloneable and Serializable interfaces. So, conversion is possible to these types as well as the same primitive types. It also explains why, as Jose says, Object[] fails at runtime.
So, given:
int[] i = new int[5];
int[] j = new int[2];
You can do this:
Object o = i;
Cloneable c = i;
java.io.Serializable s = i;
j = i;
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Thank you Jose.But why is it throwing exception?
SCJP2. Please Indent your code using UBB Code
Originally posted by Jose Botella:
Hey you thought you were going to fool the language?![]()
Originally posted by Jose Botella:
[CODE]
Hey you thought you were going to fool the language?
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Consider Paul's rocket mass heater. |