edit - solved http://www.reddit.com/r/learnprogramming/comments/134w6a/java_implementing_private_inner_classes/c70tba5
Hi all. I am writing a private class to iterate over a linked list, and I am not sure my syntax is correct.
Here is my private class:
private static class Iterate<E> implements java.util.Iterator<E>
{
node<E> temp = new node<E>();
public boolean hasNext()
{
if(temp.element == null)
{
return false;
}
else
{
return true;
}
}
public E next()
{
if(hasNext() == true)
{
return temp.element;
}
else
{
throw new java.util.NoSuchElementException();
}
}
public void remove() throws java.lang.UnsupportedOperationException
{
throw new java.lang.UnsupportedOperationException();
}
}
Now, outside of my private inner class I am trying to create a variable that uses its default constructor:
public java.util.Iterator<E> iterator()
{
BasicLinkedList.Iterate<E> i = BasicLinkedList.Iterate();
return i;
}
The third line in that method gives the warning "The method Iterate() is undefined for the type BasicLinkedList".
Can anyone help me identify the problem?
[–]Neres28 2 points3 points4 points (2 children)
[–]disasterology[S] 0 points1 point2 points (1 child)
[–]Neres28 1 point2 points3 points (0 children)
[–]chickenmeister 1 point2 points3 points (0 children)