yuttasakcom / go-type-assertion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Type Assertion

Example

package main

func main() {
	var result = "Go Type Assertion"
	display(result)

	var result2 = 100
	display(result2)
}

func display(a interface{}) {
	if s, ok := a.(string); ok {
		println(s)
		return
	}

	if i, ok := a.(int); ok {
		println(i)
		return
	}
}

About


Languages

Language:Go 100.0%