@Piet
Several reasons for devising a complete context:
1. Andy Hunt's Rule #1: Always consider context
2. OP's second version actually returned
head, which you correctly pointed out was wrong. It should have returned
head.next if the intent was to return a reference to the new Node that was added to the list.
The semantics of the implementation code are poor and potentially confusing/misleading. The name
head does not match the intent of returning the new Node. The mismatch between what the code says (
return head) and its intent imposes more cognitive load for the reader.
3. OP suggested that his second version works the same as the first version. This is not true since the first version always returns the head node, which is NOT what his second version actually (erroneously) does or seems to be intended to do (see #2)
4. As Campbell pointed out, these methods are defined as static/class methods when they probably should be instance methods of a SinglyLinkedList class. So, I wrote code that was more OO.
5. I always think about the code that you're going to have to write because of the way the API is designed. By focusing only on the code that OP provided, we lose sight of the bigger picture, which includes the code that would use these methods under consideration. Per #4, I would probably want to avoid using the static methods so I provided code that would be used in a more OO way. Which brings us back to #1.
Hope this gives you more context