How can I avoid unchecked cast warning in my generic recursive Iterator?
I don't think you can do anything about this. You have to cast here, and in the process you lose all information about the type parameter: The compiler can't know that if you have a RecursiveElement, it's always a RecursiveElement&lt;T&gt;, and "thanks" to type erasure it can't check the runtime type.