Back to questions
JuniorTheoryCommon
What happens when this program is built and run?
package main
import "fmt"
type Team struct{ Members []string }
func main() {
a := Team{}
b := a
fmt.Println(a == b)
}It does not compile
- Expecting
true:==works on a struct only when every field is comparable, and a slice field makes the whole struct incomparable. - Expecting a panic at run time: the compiler checks the field types and rejects
a == b, so the program never runs.
- How would you check that two
Teamvalues have the same members? - Could
Teambe used as a key of amap? Why or why not?