I'm not sure what I am missing.
Despite the fact that our tree descends from the AbstractList class, it is not a list in the traditional sense.
In particular, we don't have access to methods that take an element's index as an argument.
You need to override such methods and throw a new type of exception: UnsupportedOperationException.
Here's a list of them:
public String get(int index)
public String set(int index, String element)
public void add(int index, String element)
public String remove(int index)
public List<String> subList(int fromIndex, int toIndex)
protected void removeRange(int fromIndex, int toIndex)
public boolean addAll(int index, Collection<? extends String> c)
Requirements:
- An UnsupportedOperationException should occur if the get(int index) method is called.
- An UnsupportedOperationException should occur if the set(int index, String element) method is called.
- An UnsupportedOperationException should occur if the add(int index, String element) method is called.
- An UnsupportedOperationException should occur if the String remove(int index) method is called.
- An UnsupportedOperationException should occur if the subList(int fromIndex, int toIndex) method is called.
- An UnsupportedOperationException should occur if the removeRange(int fromIndex, int toIndex) method is called.
- An UnsupportedOperationException should occur if the addAll(int index, Collection<? extends String> c) method is called.
package com.codegym.task.task20.task2028;
import java.util.List;
public class Solution {
public static void main(String[] args) {
List<String> list = new CustomTree();
}
}