• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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: 22819
132
Eclipse IDE Spring 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.
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic