I have to add this statement public void removeRange (int fromIndex, int toIndex) to my ListType class.
This method should remove all the elements with indexes in the range of fromIndex (inclusive) and toIndex (exclusive). All of the succeedng elements in the list should be shifted toward the front of the list to occupy the gap left by the removed elements. This method should trown an IndexOfBoundException if either of the specified indexes is invalid.
When I try to use a Generic type E to resolved a variable in this method, I get a error. Error Message "E cannot be resolved to a variable"
My code
public void removeRange(int fromIndex, int toIndex)
{
if (fromIndex >= elements || fromIndex < 0 || toIndex >=elements || toIndex<0 || toIndex<=fromIndex)
throw new IndexOutOfBoundsException();
for( int i = fromIndex; i <toIndex; ++i)
E temp = remove(i);
// Return the element that was removed.
return;
}
I know I can't declare a generic type E object, but I don't how to get around this?