企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
类型推断在使用局部变量的时候节省了大量手工类型化,但是有时类型系统仍然需要一些帮助。事实上,它甚至不尝试推断变量(第4.1节)或者属性(第4.2节)字段,除非它有一个直接的初始化。 > Type inference saves a lot of manual type hints when working with local variables,but sometimes the type system still needs some help. In fact, it does not even try to infer the type of a variable (4.1) or property (4.2) field unless it has a direct initialization. 也有一些情况递归调用,当类型推断有限制的时候。如果一个函数递归调用它自身,它的类型还不(完全)不知道,类型推断可能推断一个错误,太详细的类型。 > There are also some cases involving recursion where type inference has limitations. If a function calls itself recursively while its type is not (completely) known yet, type inference may infer a wrong, too specialized type. 一种不同类型的限制涉及代码的可读性。如果类型推断过度使用,可能由于可见类型的缺失而难于理解程序的部分。特别是在方法签名。建议在类型推断和显式类型中找到一个好的平衡。 > A different kind of limitation involves the readability of code. If type inference is overused it might be difficult to understand parts of a program due to the lack of visible types. This is particularly true for method signatures. It is recommended to find a good balance between type inference and explicit type hints.