Skip to content

Instantly share code, notes, and snippets.

@artspb
Created September 9, 2021 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artspb/ccfd751d86123b38da4b13ee2590f3d5 to your computer and use it in GitHub Desktop.
Save artspb/ccfd751d86123b38da4b13ee2590f3d5 to your computer and use it in GitHub Desktop.
Example of a method call on a type.
package main
type Type struct{}
func (Type) foo(string) {}
func main() {
var t Type
t.foo("")
Type.foo(t, "")
}
@jonathanvila
Copy link

Now I understand..... using interfaces, with this code, there's an error on line fmt.Println(miintf.saludar("que tal"))

package main

import (
	"fmt"
)

type miintf interface {
	saludar(hola string) string
}

type objeto struct {
	titulo string
}

func (obj objeto) saludar(hola string) string {
	return hola + "adios"
}


func main() {
	var myobj objeto
	fmt.Println(myobj.saludar("how are you"))
	fmt.Println(miintf.saludar(myobj, "como estas"))	
	
	
	fmt.Println(miintf.saludar("que tal"))
}

This is the error

./prog.go:26:28: not enough arguments in call to method expression miintf.saludar
	have (string)
	want (miintf, string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment