Comments (6)
收到,谢谢。我自己再琢磨琢磨,有问题再请教。
from golang101.
status是一个新定义的类型,它当然和内置bool有所相同,但它不是内置的bool类型。
package main
import "fmt"
func main() {
type status bool
var x any = status(true)
var y any = true // bool
println(x == y) // false
fmt.Printf("%T, %T\n", x, y) // main.status, bool
type status2 = bool
var z any = status2(true);
println(z == y) // true
fmt.Printf("%T\n", z) // bool
}
from golang101.
不知道可不可以这么理解,status只是定义的一个自定义类型。我测试了,status可以输入false、数字等数据类型。
from golang101.
status可以输入false、数字等数据类型
没太懂这句话
status 是一个新类型,而status2只是一个别名(所以它不是新类型)。
from golang101.
var x any = status(true)
//这行代码,status()里输入ture、false,数字对输出结果没任何影响。
//都是false。
from golang101.
目前Go不支持从数字类型到布尔类型的转换。所以输入数字应该编译报错。
status
和bool
的底层类型一致,所以它们的值可以互相转换。
from golang101.
Related Issues (20)
- 原子操作CompareAndSwapT HOT 1
- 代码类型错误,应该是bool HOT 2
- 关于《Go Optimizations 101》 HOT 5
- Go Optimizations 101 提到的内联函数对性能的负面影响 HOT 2
- sync包 HOT 2
- 打印内容冗余 HOT 1
- 《Go 细节和小技巧 101》电子书下载链接 HOT 9
- 《Go 细节和小技巧 101》3.4 从字符串转换来的字节型切片的容量是未指定的 HOT 2
- 中文版的pdf在哪里下载? HOT 1
- 《如何优雅地关闭通道》中信号丢失的疑问 HOT 2
- 下载慢 HOT 7
- 希望增加《Go Optimizations 101》的国内付费购买渠道 HOT 1
- 访问《Go语言(基础知识)101》 报错 HOT 3
- 《Go细节和小技巧101》错别字与示例输出问题 HOT 2
- 代码问题 HOT 3
- 希望在文章的侧边增加大纲栏 HOT 2
- Hi HOT 2
- 关于【协程、延迟函数调用、以及恐慌和恢复】例子问题 HOT 2
- 考虑更新描述-类型内嵌 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from golang101.