Solution Review: Advancing the Simple Interface

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

package main
import (
type Simpler interface { // interface declaring Simple methods
Get() int
type Simple struct {
i int
func (p *Simple) Get() int {
return p.i
func (p *Simple) Set(u int) {
p.i = u
type RSimple struct {
i int
j int
func (p *RSimple) Get() int {
return p.j
func (p *RSimple) Set(u int) {
p.j = u
func fI(it Simpler) int { // switch cases to judge whether it's Simple or RSimple
switch it.(type) {
case *Simple:
return it.Get()
case *RSimple:
return it.Get()
return 99
return 0
func main() {
var s Simple
fmt.Println(fI(&s)) // &s is required because Get() is defined with the type pointer as receiver
var r RSimple

Get hands-on with 1200+ tech skills courses.