我可以将类类型声明为数组列表类型吗?

时间:2019-03-28 07:30:41

标签: java

class ArrayList<A>{
  private String name;
  A(){}
  public A(String name){
    this.name = name;
  }
  public void getter(){
    System.out.println(name);
  }
}

我想将类声明为数组列表,我不知道天气我可以做这样的事情,我只想知道。 预先感谢...

1 个答案:

答案 0 :(得分:1)

您可以通过实现List<E>接口来创建。例如:

public class UserList implements List<String> { 

@Override
    public int size() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public boolean isEmpty() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean contains(Object o) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Iterator<String> iterator() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object[] toArray() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T> T[] toArray(T[] a) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean add(String e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean remove(Object o) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends String> c) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean addAll(int index, Collection<? extends String> c) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void clear() {
        // TODO Auto-generated method stub

    }

    @Override
    public String get(int index) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String set(int index, String element) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void add(int index, String element) {
        // TODO Auto-generated method stub

    }

    @Override
    public String remove(int index) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int indexOf(Object o) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int lastIndexOf(Object o) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public ListIterator<String> listIterator() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ListIterator<String> listIterator(int index) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<String> subList(int fromIndex, int toIndex) {
        // TODO Auto-generated method stub
        return null;
    }
}

您不能提供以文字,关键字和原始(预定义)类名称开头的类名称。