Solution Review: Make a Simple Interface

This lesson discusses the solution to the challenge given in the previous lesson.

Press + to interact
package main
import (
type Simpler interface { // interface implementing functions called on Simple struct
Get() 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 interface
return it.Get()
func main() {
var s Simple
fmt.Println(fI(&s)) // &s is required because Get() is defined with a receiver type pointer

Get hands-on with 1200+ tech skills courses.