Example analysis of go language interface usage

  • 2020-05-17 05:40:50
  • OfStack

This article illustrates the use of interfaces in the go language. Share with you for your reference. The specific analysis is as follows:

First, define an interface:

type I interface{
    Get() int
    Put(int)
 
}

This defines an interface that contains two functions, Get and Put

Ok, one of my interfaces implements this interface:

type S stuct {val int}
func (this *S) Get int {
    return this.val
}
func (this *S)Put(v int) {
    this.val = v
 
}

I hope this article has been helpful to you in the programming of Go language.


Related articles: