2

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,

1
  • 1
    What Arrays-class are we talking about here? Neither java.util.Arrays nor java.lang.reflect.Array contain a toList method. However, since the reflect version is final, you can't extend it. And since both classes consist solely of static methods, do you really need to extend the class anyway? Commented Aug 3, 2010 at 18:00

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

And why can't you? I know its def constructor is private so you physically can't extend Arrays, but what's the reasoning behind it?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.