且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我必须显式提供泛型参数类型而编译器应该推断类型?

更新时间:2023-02-13 08:00:44

规范将泛型方法的类型参数推断限制为全部或全部.你不能有部分推断.

The specification limits type parameter inference for generic methods to all or nothing. You can't have partial inference.

基本原理可能是简化类型推断规则(这些规则已经非常复杂,因为它们也必须考虑重载规则).

The rationale is probably simplifying type inference rules (that are already pretty complex, as they have to take into account overloading rules too).