user3025417 user3025417 - 10 months ago 73
Java Question

Integer.valueOf() cannot find symbol in Iterator

Hi I want to write my own

over a linked list (which returns the values in the list). For some reason I get a "cannot find symbol" error when calling

import java.util.*;
class List {
private Node head;
private class IntIterator<Integer> implements Iterator<Integer>{
private Node currentNode;

private IntIterator(){
currentNode = head;

public boolean hasNext(){
return currentNode != null;

public Integer next(){
if (!hasNext()) {
return Integer.valueOf(-1); //the compiler doesnt like this..
int val = currentNode.val;
currentNode =;
return Integer.valueOf(val); //and that!

public IntIterator<Integer> iterator(){
return new IntIterator<Integer>();

I don't know how this issue can happen since the compiler doesn't complain about
in the other parts of the program.

Anyway I hope you can help me with that issue!


The problem here is that type parameter Integer hides visible type java.lang.Integer. You should write like

private class IntIterator implements Iterator<Integer>

instead of

private class IntIterator<Integer> implements Iterator<Integer>

It seems you don't understand generics completely. I suggest you to read about them.