大部分语言都用尖括号<>表示泛型,为什么golang要标新立异用中括号?

admin
发布于2025-06-20 19:00:16
376

最新的设计文档里面对这一块做了一个解释。

Why not use the syntax F like C++ and J***a? When parsing code within a function, such as v := F, at the point of seeing the < it's ambiguous whether we are seeing a type instantiation or an expression using the < operator. This is very difficult to resolve without type information. For example, consider a statement like a, b = w < x, y > (z) Withou…。

大部分语言都用尖括号<>表示泛型,为什么golang要标新立异用中括号?
X分享到微信朋友圈

打开微信,使用“扫一扫”,点击右上角“分享到朋友圈”。