views:

53

answers:

2

Hi,

I'm trying to add functionality to the Arrays-class. In my project I use the (static) methods from Arrays and have some other methods that also handle array-conversion, sorting, etc...

I'm trying to add these to an object MyArrays that extends Arrays so I can go

MyArrays.toList(foo);

but also

MyArrays.myOwnFunction(bar);

but i'm not able to extend it because Arrays-contructor has private access. I know it's not really necessary, but now I know i'm unable to do it, I realy want to. Is there any workaround for this?

thanks,

+6  A: 

You can't. And why would it matter whether you have the utility functions in one or in two classes? For the record - there is commons-lang's ArrayUtils that has additional utility methods.

Technically, you can reimplement all methods in your utility class by simply calling the corresponding methods in Arrays, but that's unneeded.

Bozho
A: 

I suggest you try using the Trove4j library. This has collections which support primitives has many of the useful Arrays/Collections methods added, like sort(). They can also be extended.

Peter Lawrey