go interface

1 接口定义:

type iface_name interface{

  //....

}

2 接口实现

// 非空接口

type iface struct {

  tab     *itab

  data    unsafe.Pointer  // data *int

}

// 空接口

type iface struct {

  _type  *_type

  data    unsafe.Pointer  // data *int

}

type _type struct {

  size          uintptr

  hash        uint32

  _unused   uint8

  align         uint8

  fieldalign   uint8

  kind         uint8

      alg           unsafe.Pointer

      gc           [2]uintptr

      _string     *string

      x            *uncommontype

      ptrto       *_type

      zero        *byte

}

参考:

http://www.cnblogs.com/concurrency/p/4311958.html

原文地址:https://www.cnblogs.com/--xiaoyao--/p/4503108.html