title: How can I implement comparable interface in go?
body: <p>I've recently started studying Go and faced next issue. I want to implement Comparable interface. I have next code:</p>
  
  <pre><code>type Comparable interface {
      compare(Comparable) int
  }
  type T struct {
      value int
  }
  func (item T) compare(other T) int {
      if item.value &lt; other.value {
          return -1
      } else if item.value == other.value {
          return 0
      }
      return 1
  }
  func doComparison(c1, c2 Comparable) {
      fmt.Println(c1.compare(c2))
  }
  func main() {
      doComparison(T{1}, T{2})
  }
  </code></pre>
  
  <p>So I'm getting error</p>
  
  <pre><code>cannot use T literal (type T) as type Comparable in argument to doComparison:
      T does not implement Comparable (wrong type for compare method)
          have compare(T) int
          want compare(Comparable) int
  </code></pre>
  
  <p>And I guess I understand the problem that <code>T</code> doesn't implement <code>Comparable</code> because compare method take as a parameter <code>T</code> but not <code>Comparable</code>.</p>
  
  <p>Maybe I missed something or didn't understand but is it possible to do such thing?</p>