7

Java 8 provides several functional interfaces in package java.util.function.

For each basic function (Function, Consumer, Predicate, Supplier...) there are other defined where the type parameter is specialized for the following primitive type: double, int, long.

This questions is about the motivation of such interfaces: Why are there primitive functions like DoubleFunction in Java 8

But why not all the primitive types are covered (e.g. float is missing)?

1 Answer 1

10

This was decided in order to prevent API size explosion. Being forced to introduce primitive specializations at all is already a pain point, so the compromise was to specialize only for the essential types, which are long and double, and additionally for int as the most prominent primitive type: the type of array indices and integer literals. All other types can be promoted to these.

In this post on the lambda-dev mailing list you can read the official statement from Brian Goetz.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.