为什么叫作IntSupplier而不是ToIntSupplier?

huangapple go评论64阅读模式
英文:

Why the name IntSupplier and not ToIntSupplier?

问题

我对javax.util.function包中默认函数接口名称的命名约定感到有些困惑:

例如,Function的原始专用版本的名称如下:
IntFunction/LongFunction/DoubleFunction,其中参数类型是指定的类型

但是,Supplier的原始专用版本的名称如下:
BooleanSupplier/DoubleSupplier/LongSupplier/IntSupplier,其中返回类型是指定的类型。

如果您比较一下java.util.function中其他接口的名称和功能,名称不应该是:
ToBooleanSupplier/ToDoubleSupplier/ToLongSupplier/ToIntSupplier吗?

英文:

I'm a little confused with the naming conventions used in default functional interface names available in javax.util.function package:

For instance, primitive specialization of Function have names like:
IntFunction/LongFunction/DoubleFunction in which argument type is of specified type

But primitive specialization of Supplier have names like:
BooleanSupplier/DoubleSupplier/LongSupplier/IntSupplier in which return type is of specified type.

If you compare the name and functionality of other interfaces in java.util.function, shouldn't the names have been like:
ToBooleanSupplier/ToDoubleSupplier/ToLongSupplier/ToIntSupplier?

答案1

得分: 2

"The word "to" in ToIntFunction, ToDoubleFunction, et al indicates that something is being converted to something else. The function's input parameters are being converted into an int/double/whatever.

The word "supplier" denotes a function that takes no input and returns some value. It supplies values. There's no input, only output.

Adding "to" would be redundant and/or misleading: redundant because the fact that it returns values is already indicated by the word "supplier"; misleading because there's no conversion. The values are generated out of thin air."

英文:

The word "to" in ToIntFunction, ToDoubleFunction, et al indicates that something is being converted to something else. The function's input parameters are being converted into an int/double/whatever.

The word "supplier" denotes a function that takes no input and returns some value. It supplies values. There's no input, only output.

Adding "to" would be redundant and/or misleading: redundant because the fact that it returns values is already indicated by the word "supplier"; misleading because there's no conversion. The values are generated out of thin air.

huangapple
  • 本文由 发表于 2020年10月28日 00:04:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64558362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定