Created
          November 10, 2016 04:58 
        
      - 
      
- 
        Save cypok/d0f988c30489d21e76ce0623385491a6 to your computer and use it in GitHub Desktop. 
    IDEA inspection is not correct
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.util.Iterator; | |
| import java.util.NoSuchElementException; | |
| final class Tree<T> { | |
| private final T elem; | |
| private final Tree<T> parent; | |
| private Tree(T elem, Tree<T> parent) { | |
| this.elem = elem; | |
| this.parent = parent; | |
| } | |
| /** Iterator from current tree element to it's root. */ | |
| public Iterator<T> toRoot() { | |
| return new Iterator<T>() { | |
| Tree<T> curr = Tree.this; | |
| @Override | |
| public boolean hasNext() { | |
| return curr.parent != null; | |
| } | |
| @Override | |
| public T next() { | |
| if (!hasNext()) { | |
| throw new NoSuchElementException(); | |
| } | |
| final T res = curr.elem; // IDEA inspection: Local variable 'res' is redundant | |
| curr = curr.parent; | |
| return res; | |
| } | |
| }; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
IDEA version information: