I am using Java.
I already have a class for a custom object called "Theme."
I have another class that contains only a Linked List of Subjects. (called subjectList)
I wrote one of the methods (called "getSubject ()") in the objectsList class, which is designed to return a Subject at a specific index in a Linked List. For this, I used ListIterator. I would create a ListIterator at the given index in LinkedList and use the .next () method.
However, the .next () method in the ListIterator returns a java.lang.Object, although I want it to return a Subject.
How to get ListIterator.next () to return a Subject?
I tried to suppress the topic, but that seems to be failing, and I read somewhere that you cannot dump unrelated objects.
This is my subjectList class:
import java.util.*;
public class subjectsList
{
private LinkedList<Subject> l;
private ListIterator itr;
public subjectsList()
{
l = new LinkedList();
}
public Subject getSubject( byte index )
{
itr = l.listIterator( index );
return itr.next();
}
public void addSubject( String nameInput, byte levelInput )
{
l.addLast( new Subject( nameInput, levelInput ) );
}
public void removeSubject( byte index )
{
itr = l.listIterator( index );
itr.next();
itr.remove();
}
}
This method is the getSubject () method.
source
share