• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Conversion.....

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..

 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this thread fits better in our SCJP forum. Moving there.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic