英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论