Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All of the methods for a <code>List</code> have <code>*List</code> receivers: (<a href="http://golang.org/pkg/container/list/" rel="nofollow">http://golang.org/pkg/container/list/</a>)</p> <pre><code>func (l *List) Back() *Element func (l *List) Front() *Element func (l *List) Init() *List ... func (l *List) Remove(e *Element) interface{} </code></pre> <p>In your example <code>l</code> is of type <code>*List</code>, so there's no need to dereference them. </p> <p>Suppose, instead, that you had something like this:</p> <pre><code>type A struct{} func (a A) X() { fmt.Println("X") } func (a *A) Y() { fmt.Println("Y") } </code></pre> <p>You are allowed to write:</p> <pre><code>a := A{} a.X() a.Y() // == (&amp;a).Y() </code></pre> <p>Or you can do the following:</p> <pre><code>a := &amp;A{} a.X() // same like == (*a).X() a.Y() </code></pre> <p>But it only works for method receivers. Go will not automatically convert function arguments. Given these functions:</p> <pre><code>func A(x *int) { fmt.Println(*x) } func B(y int) { fmt.Println(y) } </code></pre> <p>This is invalid:</p> <pre><code>A(5) </code></pre> <p>You have to do this:</p> <pre><code>var x int A(&amp;x) </code></pre> <p>This is also invalid:</p> <pre><code>var y *int B(y) </code></pre> <p>You have to do this:</p> <pre><code>B(*y) </code></pre> <p>Unlike C# or Java, when it comes to structs, Go does not make a distinction between reference and value types. A <code>*List</code> is a pointer, a <code>List</code> is not. Modifying a field on a <code>List</code> only modifies the local copy. Modifying a field on a <code>*List</code> modifies all "copies". (cause they aren't copies... they all point to the same thing in memory) </p> <p>There are types which seem to hide the underlying pointer (like a slice contains a pointer to an array), but Go is always pass by value. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload