When extending the ArrayList class you could also edit its methods, right?
I would like to extend from ArrayList and have the add() method return an Object instead of boolean (or void). So I could do this:
CustomObject o = objectList.add(new CustomObject("myObject"));
This would be the class:
public static class ObjectList extends ArrayList<CustomObject>{
public CustomObject add(CustomObject object){
super.add(object);
return object;
}
public CustomObject add(int index, CustomObject object){
super.add(index, object);
return object;
}
}
But this won't work because these methods would normally return boolean or void as been documented in the Java docs: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#add(E)
So could this be possible another way?
Thanks for your help.