fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7.  
  8. type Profile struct {
  9. Name string
  10. Language []string
  11. }
  12.  
  13.  
  14. type MyMessage interface {
  15. ShowMessage() string
  16. }
  17.  
  18. func (p *Profile) ShowMessage() string {
  19. return fmt.Sprintf("%s", p.Name)
  20. }
  21.  
  22.  
  23. func main() {
  24. me := &Profile{
  25. Name: "John Lennon",
  26. Language: []string{"Go", "Java"},
  27. }
  28. fmt.Println(me.Name) // => "John Lennon"
  29. var mes MyMessage = me
  30. mes.ShowMessage() // => 何も表示されない
  31. }
  32.  
Success #stdin #stdout 0s 790016KB
stdin
Standard input is empty
stdout
John Lennon