Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Compile Error incompatible types

$
0
0
Hi

I keep getting this error when compiling. What can be the problem?
Wrote this same while statement in C++ and it works there.

error: incompatible types
while(nodePtr.next)
^
required: boolean
found: Queue<T>.Node<T>
where T is a type-variable:
T extends Object declared in class Queue



public class Queue<T> 
{
		class Node<T>
		{
				public T element = null;
				public Node<T> next = null;
		}
		public Node<T> head;

                public void enqueue( T element)
		{
			Node<T> nodePtr = new Node<T>();
			if(isEmpty())
			{	
				head = new Node<T>();
				head.element = element;
			}
			else
			{   
				nodePtr = head;
				while(nodePtr.next)      //ERROR
				{
					nodePtr = nodePtr.next;
				}
				nodePtr.next = new Node<T>();
			}
		}
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>