Thanks <br /> <br />Regards,<br />------------------------------<br />Bijendra S. Rajput<br />SCJP 1.5<br />------------------------------
live
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from int[][] to Object
Cannot cast from Object to int[][]
i got this exception at the line Object o1 = a;
Originally posted by raja kanak:
A sub-question
int[][] a = {{1,2,}, {3,4}};
After the above code, a is a two dimensional array and a[0], a[1] are one dimensional arrays. Am i right?
If I am right, is the cast necessary in the following line?
int[] b = (int[]) a[1];
1 Object o1 = a;
2 int[][] a2 = (int[][]) o1;
cmbhatt
Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Originally posted by Chandra Bhatt:
o1 refers to a 2D array:
What if I want to assign the first of second dimension of the 2D array to one dimention array. I want to use o1 in this regard, so that my oneD array could be initialized with the first or second most dimention of the 2D array.
Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
int[][] a = {{1,2},{3,4}};
Object oneD = a[1]; // Line 1
int[] b = (int[]) oneD; // Line 2
cmbhatt
Posted By Srinivasan
Alternative solution,
int[][] a = {{1,2},{3,4}};
Object o1 =a;
int[] b = (int[]) (( (int [][])o1 )[1])
I think this is the one. you are asking.
cmbhatt
What about one glass of juice ?
Give me that "When you pass your SCJP 5.0 with 90%".
cmbhatt
Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Don't get me started about those stupid light bulbs. |