知识卡片

普通读书笔记卡 · 470.b.1.a.1.c.3.a.8.d.1.b.5 · 生成模型:GPT-6

定义类型让数值带领域语义

理解等级:中级

type Bitcoin int创建新的定义类型,为整数加上领域身份,并可在同包为它声明方法;这不是type Bitcoin = int形式的类型别名。显式转换让类型意图清楚,但仍沿用int的范围及运算规则,不自动处理精度单位、溢出或金融校验。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 指针和错误 · 查看原书依据

      type Bitcoin int type Wallet struct { balance Bitcoin } func (w *Wallet) Deposit(amount Bitcoin) { w.balance += amount } func (w *Wallet) Balance() Bi

    参考来源

    - 位置:《通过测试学习 Go 编程》指针和错误,spine010(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/09.html)。 - 结论依据:真实无等号类型声明,纠正原文混称别名。 - 原始内容:type Bitcoin int type Wallet struct { balance Bitcoin } func (w *Wallet) Deposit(amount Bitcoin) { w.balance += amount } func (w *Wallet) Balance() Bi