Search code examples
javalistarraylistlinked-listimplements

How ArrayList work with unsupportedOperationException?


I am assigned to implement my own Arraylist and Linkedlist that works very similarly to Java's provided ArrayList and LinkedList in Java.util.*, but not all of methods but some of them.

Assignment description says following: enter image description here

So it sounds like that I have to implement above code into my code for every methods that I am not going to implement. However, my source code works fine without implementing above thing. I just simply do not even mention those methods that I am not assigned to implement.

My question is, I wonder why my code works fine without mentioning above requirement in assignment description. And how can I have above function with throw new exception into my code? (to satisfy that assignment requirement anyway)

Following is my class declaration currently:

public class A1ArrayList<E>
{
...
}

Do I have to extends or implements something from Java's list API to work with that function with exception throwing?


Solution

  • Yes, you need to implement the List interface.

    public class A1ArrayList<E> implements List<E>
    {
    ...
    }