• 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

array conversion

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All this is me again..
The below code compiles and runs fine.
public class Test {
public static void main(String[] args) {

int[ ] b = { 2, 3, 1, 0 };
Object o=new Object();
o=b;

}
}
Now my point is there any practical use of converting object to array type becoz we r not even able to access array members(like length) with reference -o
though both o & b referencing to the same object(i.e int array)
Thanks
rishi
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if you want to pass the array to a method that takes only Objects?
 
Rishi Wright
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But array is also an object
 
Rishi Wright
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for the half post..
can u please give an example..becoz I think even if u pass the object reference o to any method I dont see any use..
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't see any use in passing an array as an object? How about if you wish to store an array in an ArrayList?
Normally you don't need to cast an array to an Object. But you can because of the inheritance hierarchy. And since you can, you can store a bunch of arrays in any Collection or Map object.
 
Rishi Wright
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually Iam preparing for scjp1.4 in the order of exam objectives ..so I dont have much idea about Arraylist ,Collections..
anyway...Thanks a lot Thomas ..I will keep this as note ...Hope I will get more idea when I come across Collections topic...
rishi
 
reply
    Bookmark Topic Watch Topic
  • New Topic