Re: Extending Arrays
Roedy Green wrote:
On Thu, 17 Apr 2008 13:17:41 -0700 (PDT), Chase Preuninger
<chasepreuninger@gmail.com> wrote, quoted or indirectly quoted someone
who said :
I wonder what would would happen if u would create a class extending
an array.
You have two problems:
the name of the class is no accessible in ordinary java. You would
have to write byte code.
The class is almost certainly final.
Consider writing an HAS-A rather than IS-A implementation, the way
ArrayList does.
A Java array is actually *not* a real class. It is a special type of
primitive. From the JVM point of view, it does not have a field called
length, there is actually a special op-code to access the array length...
Also, an array reference is assignable to Object, java.io.Serializable,
and Clonable reference variables, but in many regards is very different
than other "classes".
The other thing to consider is that arrays are low-level
building-blocks, and you should avoid using them in all but the
lowest-level abstractions (such as Collection API implementations).
Anything else should use abstractions (such as the Collections API) in
place of these primitives.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>