Iterable
is a generic interface. That means, unless you give it a type parameter, it will be a raw type, and the underlying data will be treated as Object
.
Change this:
class InorderItr implements Iterator
class InorderTreeIterator implements Iterable
to the following:
class InorderItr implements Iterator<Integer>
class InorderTreeIterator implements Iterable<Integer>
This way, it is no longer a raw type (and that get rids of the warnings of unchecked and unsafe operations the compiler gives you currently), and it tells the compiler that the Iterator
will have its underlying data type be Integer
(since the type parameter in the Iterator
interface is its underlying data type), so the type matches.