As an experiment, I tried to extend an int
-array like this:
public class IntArrayExtension extends int[]{
// additional fields and methods.
}
to add some methods related to sorting, swapping, sub-array building etc. in the class itself. But I got this error while compiling:
IntArrayExtension.java:1: unexpected type
found : int[]
required: class
public class IntArrayExtension extends int[]{
^
1 error
I am curious to know: why Java does not allow to extend an array?