• Post Reply Bookmark Topic Watch Topic
  • New Topic

How are arrays maintained  RSS feed

 
Gaurav Singh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first post, hope this is the right forum.

I have been told that arrays are objects, but I am not able to find any concrete implementation for the same. I guess there myst be some class/interface defined somewhere(in java.lang package obviously) which should have some concrete implementation and contain variables such as length etc.
I have gone through the javadocs of JDK1.5 but am not able to find any such thing.

This is somewhat confusing. Can somebody please explain as to how exactly arrays are created and maintained. I am not looking for syntax etc, this question is more about understanding

Thanks
Gaurav
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays are objects but they are also implemented as language feature like primitives. Since it is an object, you can do things associated with objects including:

synchronize on them
serialize
Clone
manipulate them through reflection.

what you can't do, though, is see how they are implemented or inherit from
them.

Arrays are special:
They can violate the first rule of object serialization: "The object to be persisted must implement the Serializable interface or inherit that implementation from its object hierarchy." well, violate is a strong word because they just pass this requirement along to their member objects

Arrays implement the cloneable interface. when you call clone() on them, there is a special override so that the CloneNotSupportedException is not thrown.

you can interrogate an object with object.getClass().isArray(); to see if it is an array.

To get around the lack of a java array implementation, the Reflection package has its own array object, with a bunch of methods that would be great to have in a regular array.

calling array.toString() won't do toString() on the contents like Collections can.

mostly, I learned this from Here
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, there are ways to interrogate an array class to find out things about it's implementation as described in The Mysterious Java Array

for example,
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!