|
-
May 15th, 2003, 02:05 PM
#1
Thread Starter
Lively Member
Why are Arrays Object [Sort of Resolved]
I understand that everything in Java is an object. But what are the advantages of Arrays being objects too? Any special significance to it?
Last edited by onbliss; May 28th, 2003 at 04:22 PM.
-
May 15th, 2003, 02:58 PM
#2
-
May 15th, 2003, 03:51 PM
#3
Dazed Member
An array treated and manipulated as an object in Java not only gains the advantages that BootKing has pointed out but also given an arbitrary object x, you can find out if the object x is an array and, if so, what type of array it is.
Code:
Class type = x.getClass();
if(type.isArray()){
Class elementType = type.getComponentType();
}
-
May 17th, 2003, 04:07 AM
#4
Being an object also allows arrays to be stored in collections like ArrayList.
And it allows them to be passed as object, as is necessary because an int[] (or other arrays of basic types) can't be cast to Object[], so the System.arraycopy method would need to be overloaded instead of accepting Object arguments.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|