You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These will include varargs overloads, so that there is no fixed limit on the collection size. However, the collection instances so created may be tuned for smaller sizes. Special-case APIs (fixed-argument overloads) for up to ten of elements will be provided. While this introduces some clutter in the API, it avoids array allocation, initialization, and garbage collection overhead that is incurred by varargs calls. Significantly, the source code of the call site is the same regardless of whether a fixed-arg or varargs overload is called.
翻译一下:
这些将包括可变参数重载,因此集合大小没有固定限制。然而,如此创建的集合实例可以调整为更小的尺寸。将提供最多十个元素的特殊情况 API(固定参数重载)。虽然这会给 API 带来一些混乱,但它避免了由 varargs 调用引起的数组分配、初始化和垃圾收集开销。值得注意的是,无论调用的是固定参数重载还是可变参数重载,调用站点的源代码都是相同的。
结论: 虽然这种做法让 API 有点混乱,但避免了由 varargs 调用引起的数组分配、初始化和垃圾收集开销。
The text was updated successfully, but these errors were encountered:
代码如下:
Java 提案里有提到这个: https://openjdk.org/jeps/269
其中关键的一段:
翻译一下:
这些将包括可变参数重载,因此集合大小没有固定限制。然而,如此创建的集合实例可以调整为更小的尺寸。将提供最多十个元素的特殊情况 API(固定参数重载)。虽然这会给 API 带来一些混乱,但它避免了由 varargs 调用引起的数组分配、初始化和垃圾收集开销。值得注意的是,无论调用的是固定参数重载还是可变参数重载,调用站点的源代码都是相同的。
结论: 虽然这种做法让 API 有点混乱,但避免了由 varargs 调用引起的数组分配、初始化和垃圾收集开销。
The text was updated successfully, but these errors were encountered: