Skip to content

Instantly share code, notes, and snippets.

@VictorDenisov
Created November 17, 2021 23:08
Show Gist options
  • Save VictorDenisov/6de936dc0c6dcd49d32424b28dc6da7c to your computer and use it in GitHub Desktop.
Save VictorDenisov/6de936dc0c6dcd49d32424b28dc6da7c to your computer and use it in GitHub Desktop.
Golang composition
package main
import (
"fmt"
)
type A struct {
}
func (a *A) hello() {
fmt.Printf("Hello all\n")
}
type B struct {
a A // This code works if this is unnamed field.
}
func main() {
b := &B{}
b.hello()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment