Skip to content

Instantly share code, notes, and snippets.

@ladrift
Last active August 4, 2016 14:56
Show Gist options
  • Save ladrift/96d83c82750d2f0d0feb2a3240d08d09 to your computer and use it in GitHub Desktop.
Save ladrift/96d83c82750d2f0d0feb2a3240d08d09 to your computer and use it in GitHub Desktop.
package main
type Mutex struct{}
func (m *Mutex) Lock() {}
func (m *Mutex) Unlock() {}
type PtrMutex *Mutex
func main() {
m := &Mutex{}
m.Lock()
var pm PtrMutex
//pm.Lock() // illegal: pm don't have method Lock.
pm1 := (*Mutex)(pm)
pm1.Lock() // But the underlying type has its methods.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment