基本型別轉換

Go 中有兩種基本的型別轉換樣式:

// Simple type conversion
var x := Foo{}    // x is of type Foo
var y := (Bar)Foo // y is of type Bar, unless Foo cannot be cast to Bar, then compile-time error occurs.
// Extended type conversion
var z,ok := x.(Bar)    // z is of type Bar, ok is of type bool - if conversion succeeded, z has the same value as x and ok is true. If it failed, z has the zero value of type Bar, and ok is false.