I often thought that it would be nice to let arrays be used as the right objects with my own methods instead of relying on helper classes like arrays, arrays, and ArrayUtils objects.
For example:
ints.sort(); // Arrays.sort(ints); int[] onemore = ints.add(8); // int[] onemore = ArrayUtils.add(ints, 8);
I am sure that I am not the first with this idea, but I had problems finding others who wrote about this before. Can someone help me with some links on this topic?
Is this idea a good or bad idea and why?
How easy is it to implement?
Some other examples may include (but not depend on them, they are extraneous to the issue itself):
int[] ints = {5,4,3,2,1}; // Arrays.sort (ints); ints.sort(); // int pos = Arrays.asList(ints).indexOf (5); // int pos = ArraysUtils.indexOf (ints, 5); int pos = ints.indexOf (5); // Arrays.reverse (ints); ints.reverse(); Array<Integer> array = ints; // cast to super class. // int length = Array.getLength (array); int length = array.getLength(); // Object n = Array.get (array, 3); Object n = array.get (3); // Array.set (array, 3, 7); array.set (3, 7); Object obj = array; // if (obj instanceof int[]) // System.out.println(Array.toString((int[]) obj)); // else if (....) System.out.println (obj);
java arrays
paxdiablo
source share