LinkedList<T> Java

  • Thread starter Live4eva_2
  • Start date
  • #1
28
0

Main Question or Discussion Point

Could someone check the following 3 classes for me please?

Java:
public class LinkedList<T>
{
    public Node<T> first;
    public Node<T> last;
    protected class Node<T>
    {
        public Node<T> next;
        public Node<T> last;

    }
    public class Iterator<T>
    {
        protected Node<T> current;
        protected Node<T> previous;

    }

}
I've only included the classes and variables in order to illustrate the visibility.
when I complile I'm getting the msg that "Node<T> current" isn't available in LinkedList<T> class...why not !?Am I only allowed one inner class?Also i ensured that my iterator was constructed within the LinkedList constructor so i dont think that it could be a problem with instantiating the iterator object.
 
Last edited by a moderator:

Answers and Replies

  • #2
33,508
5,193
The current member of Iterator<T> is protected, so it is accessible only to other members of that class or subclasses of that class. It is not accessible to outer scopes, which would include the LinkedList class.

I'm reasonably sure about what I've said, but I haven't really written any Java code for many years. If anybody has an opposing view, please jump in.
 

Related Threads on LinkedList<T> Java

  • Last Post
Replies
4
Views
22K
Replies
2
Views
10K
  • Last Post
Replies
9
Views
2K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
11
Views
86K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
12
Views
619
  • Last Post
Replies
9
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
4
Views
2K
Top