Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Extending Arrays

Reply
Thread Tools

Extending Arrays

 
 
Chase Preuninger
Guest
Posts: n/a
 
      04-17-2008
I wonder what would would happen if u would create a class extending
an array.

class CustomArray extends Object[ ]
{
}
 
Reply With Quote
 
 
 
 
Andrea Francia
Guest
Posts: n/a
 
      04-17-2008
Chase Preuninger wrote:
> I wonder what would would happen if u would create a class extending
> an array.
>
> class CustomArray extends Object[ ]
> {
> }


It would be never more useful than implementing List.

class CustomArray implements List {
}

--
Andrea Francia
http://www.andreafrancia.it/
 
Reply With Quote
 
 
 
 
Chase Preuninger
Guest
Posts: n/a
 
      04-17-2008
i know, just wondering if it would work
 
Reply With Quote
 
Andrea Francia
Guest
Posts: n/a
 
      04-17-2008
Chase Preuninger wrote:
> i know, just wondering if it would work

Probably you could override these two methods

public Object operator[](int index);
public void operator[](int index, Object value);

But you could not change the 'length' because it is final.

--
Andrea Francia
http://www.andreafrancia.it/
 
Reply With Quote
 
Jan Thomä
Guest
Posts: n/a
 
      04-17-2008
On Thu, 17 Apr 2008 22:06:49 GMT Andrea Francia wrote:

> Chase Preuninger wrote:
>> i know, just wondering if it would work

> Probably you could override these two methods
>
> public Object operator[](int index);
> public void operator[](int index, Object value);
>
> But you could not change the 'length' because it is final.


Errm, we are talking Java here, right ?
 
Reply With Quote
 
Andrea Francia
Guest
Posts: n/a
 
      04-17-2008
Jan Thomä wrote:
> On Thu, 17 Apr 2008 22:06:49 GMT Andrea Francia wrote:
>
>> Chase Preuninger wrote:
>>> i know, just wondering if it would work

>> Probably you could override these two methods
>>
>> public Object operator[](int index);
>> public void operator[](int index, Object value);
>>
>> But you could not change the 'length' because it is final.

>
> Errm, we are talking Java here, right ?


Hypothetic Java

--
Andrea Francia
http://www.andreafrancia.it/
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      04-18-2008
Andrea Francia <> writes:

> Jan Thomä wrote:
>> Errm, we are talking Java here, right ?

>
> Hypothetic Java


I hypothetic Java, you can do anything you want

In real Java, you are very far from being able to extend array
types or overload operators.

/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-18-2008
On Thu, 17 Apr 2008 13:17:41 -0700 (PDT), Chase Preuninger
<> 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.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Chase Preuninger
Guest
Posts: n/a
 
      04-18-2008
I am not took good at reflection, but would it be possible the change
the size of an array with reflection.
 
Reply With Quote
 
Jan Thomä
Guest
Posts: n/a
 
      04-18-2008
On Thu, 17 Apr 2008 19:01:49 -0700 (PDT) Chase Preuninger wrote:

> I am not took good at reflection, but would it be possible the change
> the size of an array with reflection.


No. If you want to have resizable collections you should go for an
ArrayList or something similar. That's what they are made for.

Jan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
consistency: extending arrays vs. multiplication ? Soeren Sonnenburg Python 11 07-25-2005 08:31 PM
char arrays and integer arrays... why the difference? Bill Reyn C++ 3 06-22-2004 12:01 PM
Arrays.asList() returning java.util.Arrays$ArrayList Alexandra Stehman Java 5 06-17-2004 06:04 PM
initializing arrays of arrays Mantorok Redgormor C Programming 4 09-11-2003 02:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57