大家好,我是煎鱼。 近期我们在分享《3 件与 Go 开发者有关的大小事》时,里面有一部分有提到 Go 泛型的约束类型语法又又又变了。 在评论区里看到不少的读者朋友大呼泛型的新类型约束语法挺丑,不如原本的好… 如下: 为此,今天煎鱼就带大家来看看,为什么会发生泛型的新语法会这种改变? 问题背景 原本 @Ian Lance Taylor 设计的的泛型类型关键字如下: type T interface { type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64, complex64, complex128, string } 看起来好像非常 “顺眼”。但在《proposal: Go 2: sum types using interface type lists》中社区进行了热烈的讨论。