The following code gives me a 'Dead Code' warning in Eclipse:
private void add(Node<E> n, E element) {
Node<E> e = new Node<E>(element);
if (n == null)
root = e;
else if (n.compareTo(e) > 0)
if (n.hasLeft())
add(n.getLeft(), element);
else
n.setLeft(e);
else if (n.hasRight())
add(n.getRight(), element);
else
n.setRight(e);
balance(e);
}
The warning appears at the line that says root = e;
.
I looked up dead code and found that it is code hat has no effect and will therefore be ignored by the java compiler.
However, this root is a private field in my class and therefore it is necessary for the function of my program that I do this.
Is the compiler really going to ignore this? How can I stop that? Why does it think it is dead code?