Reversing a singly-linked list
<p>On a job interview I was asked to reverse a single linked list. Here is what my solution was:</p>

<pre><code>public class E&lt;T&gt;{
    private E&lt;T&gt; next;
    private T val;

    private E(T val) {
        this.val = val;
    }

    public static &lt;T&gt; E&lt;T&gt; createNode(T val){
        return new E&lt;T&gt;(val);
    }

    public E&lt;T&gt; add(E&lt;T&gt; next){
        E&lt;T&gt; current = this;
        while(current.next != null){
            current = current.next;
        }
        current.next = next;
        return this;
    }

    public E&lt;T&gt; reverse(){
        if(this.next == null)
            return this;
        E&lt;T&gt; previous = new E&lt;&gt;(this.val); //&lt;----- HERE
        E&lt;T&gt; current = this.next;
        while(current != null){ 
            E&lt;T&gt; tmp = current.next;
            this.val = current.val;
            this.next = previous;
            current.next = previous;
            previous = current;
            current = tmp;
        }
        return this;
    }
}
</code></pre>

<p>But it does look ugly. The issue I could not understand how to deal with was that we initially had only <code>this</code> reference which we could not assign to anything (we just ended up with a cycle then). That was the reason I created a new node. But it looks as a terrible workaround. Is there a "true way" to do that?</p>