This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Query:Data Type  Conversions  :Array  to Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query:Data Type  Conversions  :Array  to Object" Watch "Query:Data Type  Conversions  :Array  to Object" New topic
Author

Query:Data Type Conversions :Array to Object

Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
Hi,
In java ,
We can convert(automatically convertd) array reference to object of Object class
ie
Object o;
int arr[]={1,2,3};

o=arr; //this line is legal

Now ,o points to same memory location ,to which arr was referencing.
Can we access to the data (list to value or array data) through Object o.
thnx
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
No, o can only access the methods of Object.

You will have to cast o to an array reference before you can access the elements with the array access operator.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Lucky,

Although you can do the following:





cmbhatt


cmbhatt
 
 
subject: Query:Data Type Conversions :Array to Object
 
Similar Threads
Data Types Converison :Array to Object
Array problem
local arrays
nullPointerException
[Help] Sending List<String> via Socket.