同じ構造体
package main
import "fmt"
func main() {
type pokemon struct {
name string
species string
}
pokemon1 := pokemon{
"フシギダネ",
"たねポケモン",
}
pokemon2 := pokemon{
"フシギソウ",
"たねポケモン",
}
fmt.Println(pokemon1)
fmt.Println(pokemon2)
fmt.Println(pokemon1.name == pokemon2.name)
fmt.Println(pokemon1.species == pokemon2.species)
}
違う構造体
- 名前が違っても、型が同じであれば比較できる
- 名前が同じでも、型が違う場合は比較できない
package main
import "fmt"
func main() {
type firstPokemon struct {
name string
species string
text1 string
hoge string
}
type secondPokemon struct {
name string
species string
text2 string
hoge int
}
pokemon1 := firstPokemon{
name: "フシギダネ",
species: "たねポケモン",
text1: "test",
hoge: "hoge",
}
pokemon2 := secondPokemon{
name: "フシギソウ",
species: "たねポケモン",
text2: "test",
hoge: 999,
}
fmt.Println(pokemon1)
fmt.Println(pokemon2)
fmt.Println(pokemon1.name == pokemon2.name)
fmt.Println(pokemon1.species == pokemon2.species)
fmt.Println(pokemon1.text1 == pokemon2.text2)
fmt.Println(pokemon1.hoge == pokemon2.hoge)
}