GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • XGo
  • Tutorials

This view

  • Original page
  • New address

GeezerVison is showing tutorial.xgo.dev — XGo by Tutorials: Type Switches

  • XGo
  • Tutorials
  • Type Switches

Type Switches

A type switch compares types instead of values. You can use this to discover the type of an interface value. In this example, the variable t will have the type corresponding to its clause.

whatAmI := func(i interface{}) { switch t := i.(type) { case bool: println "I'm a bool" case int: println "I'm an int" default: printf "Don't know type %T\n", t } } whatAmI true whatAmI 1 whatAmI "hey"
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.