Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Go is statically typed, meaning that Go knows what the types of your values are even at compile time, and can tell whether they're being used appropriately.
Go is statically typed, meaning that Go knows what the types of your values are even at compile time, and can tell whether they're being used appropriately.
fmt.Println("hello" + 527) // invalid operation: "hello" + 527 (mismatched types string and int)
This code will print the types of several Go values:
package main
import (
"fmt"
"reflect"
)
func main() {
fmt.Println(reflect.TypeOf(1)) // int
fmt.Println(reflect.TypeOf(1.5)) // float64
fmt.Println(reflect.TypeOf("hello")) // string
fmt.Println(reflect.TypeOf(false)) // bool
fmt.Println(reflect.TypeOf(net.IPv4(127, 0, 0, 1))) // net.IPv4
fmt.Println(reflect.TypeOf(time.Now())) // time.Time
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up