Modify inbuilt Java functions

Is it possible to change how functions inherent to java function without modifying the files? For example, I'd like to modify java.util.Arrays.toString() to throw an error if used on anything but a 1D array, for convenience. Is this possible?

Sorry if it's been asked before, couldn't find it on google. Thanks.

Jon Skeet
people
quotationmark

No, you can't do that. I suggest you write your own separate class, given that you want different functionality.

Obviously Java allows you to override non-final instance methods in classes, but even then the clients would need to know to create an instance of the subclass... and restricting the set of inputs that a method can accept is a breaking change anyway. And seeing as this is a static method in the first place... basically, the normal mechanisms for custom behaviour aren't going to help you.

people

See more on this question at Stackoverflow