recently, learning go wants to judge whether two variables are equal or not. It is found that if the two variables are assigned different types, they will directly report an error when using if judgment
..\test.go:123:8: invalid operation: c == d (mismatched types int and float64)
here is my code to ask the bosses how to judge if this is the case
package main
import (
"fmt"
"reflect"
)
func main() {
c := 1
d := 1.1
ct := reflect.TypeOf(c)
dt := reflect.TypeOf(d)
fmt.Println("!!!!!!!!!!!!!!!!!!")
fmt.Println(ct)
fmt.Println(dt)
if ct == dt {
fmt.Println("")
if c == d {
fmt.Println("")
} else {
fmt.Println("")
}
} else {
fmt.Println("")
}
}