I want to extend the ArrayList class to create a collection which doesn't hold duplicate element and use array internally to store. SetUniqueList
stores unique element, but I want to add more functionality.
I am stuck in the method writeObject
and readObject
. This is the implementation in ArrayList
:
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException{
int expectedModCount = modCount;
s.defaultWriteObject();
s.writeInt(elementData.length);
for (int i=0; i<size; i++)
s.writeObject(elementData[i]);
if (modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
}
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
int arrayLength = s.readInt();
Object[] a = elementData = new Object[arrayLength];
for (int i=0; i<size; i++)
a[i] = s.readObject();
}
Clearly I cannot access private transient Object[] elementData;
. I am puzzled that should I create class like ArrayList
, not extending it, or there is any other artcitectural way to do this?
Update
I need to use subList
so that changes in the sub list are reflected in this list.