可选参数? [英] Optional Parameters?
问题描述
Go没有可选参数< a href =http://golang.org/doc/faq#overloading =noreferrer>它也不支持方法重载:
如果
不需要像
那样进行类型匹配,则方法调度会被简化。使用其他语言的经验
告诉我们,有多种
方法具有相同的名称,但
不同的签名偶尔会有
有用,但它也可能是
混淆和在实践中很脆弱。
仅通过名称进行匹配并且要求
类型的一致性是Go类型
系统中的一个重要
简化决策。
Can Go have optional parameters? Or can I just define two functions with the same name and a different number of arguments?
Go does not have optional parameters nor does it support method overloading:
Method dispatch is simplified if it doesn't need to do type matching as well. Experience with other languages told us that having a variety of methods with the same name but different signatures was occasionally useful but that it could also be confusing and fragile in practice. Matching only by name and requiring consistency in the types was a major simplifying decision in Go's type system.
这篇关于可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!