Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trying to extend AbstractList

807606Jun 9 2007 — edited Jun 9 2007
Any help is appreciated. I am unsuccessfully trying to extend an AbstractList. I have looked at Java documents regarding AbstractList as well as the skimpy Sun Custom Collection Tutorial, but I'm still drawing blank.

A couple of basic questions: Is my internal representation of the array a standard Array? something like myJ below? And if so, since I want to make this a variable sized collection, the docs state that I must override the add and remove methods. If my internal representation is a nonvariable sized array, how do I go about doing this? Or am I way off base to begin with?
import java.util.AbstractList;

public class JunkList extends AbstractList<Junk>
{
    private final Junk[] myJ;

    public JunkList()
    {
        myJ = new Junk[0];
    }
    
    @Override
    public Junk get(int index)
    {
        return myJ[index];
    }
    
    @Override
    public Junk set(int index, Junk ele)
    {
        Junk oldValue = myJ[index];
        myJ[index] = ele;
        return oldValue;
    }

    @Override
    public int size()
    {
        return myJ.length;
    }
}
Many thanks in advance!
/Pete
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 7 2007
Added on Jun 9 2007
7 comments
306 views