Solution Review: Make a Simple Interface
This lesson discusses the solution to the challenge given in the previous lesson.
package mainimport ("fmt")type Simpler interface { // interface implementing functions called on Simple structGet() intSet(int)}type Simple struct {i int}func (p *Simple) Get() int {return p.i}func (p *Simple) Set(u int) {p.i = u}func fI(it Simpler) int { // function calling both methods through interfaceit.Set(5)return it.Get()}func main() {var s Simplefmt.Println(fI(&s)) // &s is required because Get() is defined with a receiver type pointer}
Get hands-on with 1400+ tech skills courses.