golang convert interface to concrete type
type Person struct {
firstName string
lastName string
}
func printIfPerson(object interface{}) {
person, ok := object.(Person)
if ok {
fmt.Printf("Hello %s!n", person.firstName)
}
}
golang convert interface to concrete type
type Person struct {
firstName string
lastName string
}
func printIfPerson(object interface{}) {
person, ok := object.(Person)
if ok {
fmt.Printf("Hello %s!n", person.firstName)
}
}
golang interface to int
var myInt interface{}
myInt = 8
toInt, ok := myInt.(int)
fmt.Println(toInt, ok) // 8 true
toString, ok := myInt.(string)
fmt.Println(toString, ok) // "" false
interface to int golang
iAreaId := val.(int)
iAreaId, ok := val.(int) // Alt. non panicking version
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us