Confused about linked list deletion
<p>I am trying to implement the deletion function in </p>

<pre><code>public static boolean delete(Object d, ListElement head){
ListElement p=find(d,head);
if(p.data==null){return false;}
else {
    System.out.println("Delete Successfully!");
    if(head.data==d){head=head.next;}
    else{
    while(head.next.data!=d){
        head=head.next;
    }
    head.next=head.next.next;}
    return true;}

}
</code></pre>

<p>This function basically check if the element <code>d</code> is in the list, 
-if <code>not-&gt;return false;</code></p>

<p>-else check whether the element is the first element of the list, if <code>true</code>, change the head to its <code>next</code>,</p>

<p>-else traverse to the list element in front of it. </p>

<p>The problem is case the element to delete is the first element, such as boolean <code>s=ListElement.delete(1,d);</code> I cannot use "<code>head=head.next;</code>" to assign new value to head. <strong>But java is passed by reference, why cannot I change that?</strong></p>

<p>//actually I found my question is whether we can change the reference passed to the function  inside the function
like:</p>

<pre><code>    void fun(dog a){
    a=new dog("Po");
}
main()   
{dog b=new dog("Jo");fun(b);}
</code></pre>

<p>//so will b be changed?</p>
