另一个示例:通用类型推断。
类型推断——包括精确和推测两种方式。
即使使用类型推断,还是需要多余的类型信息。
Even with type inference, redundant type information is needed.
怎么是这个函数的类型推断?
其中一些,比如已经讨论过的类型推断,可以随意使用。
Some of these, such as type inference, as discussed, come for free.
返回类型是推断出的,我们会看到,这会是一个潜在的问题所在。
The return type is inferred, which is a potential problem, as we will see.
编译器应该为底部赋值中的T推断什么类型?
What type should the compiler infer for T in the assignment at the bottom?
注意,String类型是被推断出来的。
也可以省略类型参数,编译器将推断出该参数。
You can also omit the type argument and the compiler will infer it.
也可以省略类型参数,编译器将推断出该参数。
You can also omit the type argument and the compiler will infer it.
应用推荐