Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion.....

 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is from the SCJP6 book...



I've 2 question

1. Is this possible "(int[]) a[1]" ...or is it just to confuse it.

2. At line 3, why it didn't show that o1 is an array of array not array, why it was shown at the runtime..

 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If 'a' is a two dimension array (int[][]) then each element is a one dimension array (int[]).
So casting this way is not necessary; yes, just to confuse you. On your second question,
the compiler only knows 'o1' as an Object so it thinks the cast is okay. But at run time the
JVM knows that 'o1' is a 2-d array.

Jim ... ...
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Hoglund wrote:If 'a' is a two dimension array (int[][]) then each element is a one dimension array (int[]).
So casting this way is not necessary; yes, just to confuse you. On your second question,
the compiler only knows 'o1' as an Object so it thinks the cast is okay. But at run time the
JVM knows that 'o1' is a 2-d array.

Jim ... ...


Ok buddy thanks a lot for the solution, so even you are preparing for the SCJP exam (on your signature), same here buddy
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this thread fits better in our SCJP forum. Moving there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic