How to implement an interface with a type in Go

1 Answer

0 votes
package main

import "fmt"

type IN interface {
	F()
}

type ST struct {
	str string
}

func (s ST) F() {
	fmt.Println(s.str)
}

func main() {
	var in IN = ST{"Go"}
	
	in.F()
}


/*
run:

Go

*/

 



answered Mar 30, 2020 by avibootz

Related questions

1 answer 240 views
1 answer 333 views
2 answers 324 views
324 views asked Aug 16, 2020 by avibootz
1 answer 223 views
1 answer 262 views
1 answer 238 views
238 views asked Apr 27, 2017 by avibootz
1 answer 265 views
265 views asked Jan 7, 2016 by avibootz
...