类SubList()必须被称为abstract或在'List'中实现抽象方法'listIterator'

时间:2016-03-12 01:32:31

标签: java intellij-idea

Intellij抛出此错误,但我正在实现它。这是我的主类MyList的子类,它基于ArrayList。

Class SubList()必须被称为abstract或在'List'中实现抽象方法'listIterator'

private class SubList extends MyList<AnyType>
{
    private List<AnyType> original;
    private int offset;
    private int size;


    public MyList<AnyType> subList( int from, int to )
    {
        return new SubList( this, from, to );
    }

    public SubList( int from, int to )
    {  if( from < 0 || to > MyList.this.size( ) ) throw new IllegalArgumentException( from + " " + to + " " + MyList.this.size( ) );
        original = MyList.this; offset = from; size = to - from; }

    public SubList( SubList sub, int from, int to )
    { if( from < 0 || to > sub.size( ) ) throw new IllegalArgumentException( from + " " + to + " " + sub.size( ) );
        original = sub.original; offset = sub.offset + from; size = to - from; }

    public int size( )
    { return size; }

    public AnyType get( int idx )
    { return original.get( offset + idx ); }

    public AnyType set( int idx, AnyType x )
    { return original.set( offset + idx, x ); }

    public boolean add( AnyType x )
    { throw new UnsupportedOperationException( ); }

    public AnyType remove( int idx )
    { throw new UnsupportedOperationException( ); }

    public boolean remove( Object x )
    { throw new UnsupportedOperationException( ); }

    public boolean contains( Object x )
    { for( AnyType item : this ) if( item.equals( x ) ) return true; return false;  }


    public ListIterator<AnyType> listIterator( int idx )
    { return original.listIterator( offset + idx ); }

    public Iterator<AnyType> iterator( )
    { return original.listIterator( offset ); }
}

1 个答案:

答案 0 :(得分:0)

List中有两种方法:listIterator(int)listIterator()。你似乎压倒了前者,但不是后者。

相关问题