dongshui9690 2019-08-07 02:01
浏览 234
已采纳

(* DefaultHandler)(nil)是什么意思,其中DefaultHandler是一个结构? [重复]

I can understand whole last line of code meaning: It provides a static (compile time) check that *DefaultHandler satisfies the EasygateHandler interface. But I cannot understand what's the meaning of (*DefaultHandler)(nil) and what's the difference with (*DefaultHandler)()

type DefaultHandler struct {
    log logrus.FieldLogger
    svc *service.DefaultResolver
}

var _ easygate.EasygateHandler = (*DefaultHandler)(nil)
</div>
  • 写回答

1条回答 默认 最新

  • dongxiong1941 2019-08-07 02:54
    关注

    The expression (*DefaultHandler)(nil) is a conversion from an untyped nil to a zero value of type *DefaultHandler.

    Conversions are of the form T(x) where T is a type and x is a value that can be converted to type T. In this example, T is *DefaultHandler and x is nil. The parenthesis around *DefaultHandler are required to distinguish the conversion to a pointer type from a dereference of a a conversion to the non-pointer type.

    The expression (*DefaultHandler)() is not valid Go syntax.

    The value &DefaultHandler{} can also be used if DefaultHandler is a type with composite literal syntax. The conversion pattern works for all types.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程