使用型別斷言斷定某個介面是否是指定的型別
if這種簡化形式:
if _,ok:=x.(T);ok{
}
type-switch 型別判斷形式
switch t := x.(type) {
case int:
fmt.Printf(1)
case nil:
fmt.Printf(2)
default:
fmt.Printf(3)
}
型別斷言使得相同介面的變數在不同的時刻表現出不同的行為,這就是多型的本質,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/192018.html
標籤:其他
