Created
November 17, 2021 23:08
-
-
Save VictorDenisov/6de936dc0c6dcd49d32424b28dc6da7c to your computer and use it in GitHub Desktop.
Golang composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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