Re: compare two byte[] 's
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Wed, 17 Dec 2008 15:25:53 -0500
Mark Space wrote:
What does bother me is the lack of utility built into arrays. Changing #equals() or #clone() now would likely be too difficult, but I don't see the harm in adding new methods. All of the very similar overloaded methods in java.util.Arrays, for example, would fit neatly into instance methods of an array class. I honestly can't figure out why this hasn't been done.
This is one possible reason:
Since each array is its own special class, the virtual machine has to synthesize special class objects for arrays. The developers made a choice to keep these objects as small as possible. One thing that could really bloat these objects would be to have to define methods for /every/ single array type.
java.util.Array's toString method has 75 bytes for Object[] and 72 for <primitive>[]. The hashCode methods are between 45 and 56 bytes. The equals methods are between 54 bytes and 78 bytes.
Even ignoring whether or not you want equals to be == or .equals equality, that's 206 bytes for just the bytecode operations for an Object[] class. I'm not including the overhead for method definitions.
I'm willing to bet that the code for Object.clone() special-cases array cloning, just to avoid having to redefine all of these methods.
I'd also imagine that this setup makes the code generation easier: there's only a few bytes that have to be modified, even across primitive and reference type arrays.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.
- Follow-Ups:
- Re: compare two byte[] 's
- From: Mark Space
- Re: compare two byte[] 's
- From: Tom Anderson
- Re: compare two byte[] 's
- References:
- compare two byte[] 's
- From: harryos
- Re: compare two byte[] 's
- From: Sigfried
- Re: compare two byte[] 's
- From: Lew
- Re: compare two byte[] 's
- From: Mark Space
- Re: compare two byte[] 's
- From: Daniel Pitts
- Re: compare two byte[] 's
- From: Mark Space
- compare two byte[] 's
- Prev by Date: Re: Painting in JPanel
- Next by Date: Re: compare two byte[] 's
- Previous by thread: Re: compare two byte[] 's
- Next by thread: Re: compare two byte[] 's
- Index(es):
Relevant Pages
|
Loading