intermediateFunctional Programming
What are primitive functional interfaces in Java, and why do they exist?
Primitive functional interfaces — IntPredicate, IntFunction, IntConsumer, IntSupplier, and their long/double equivalents — are specialized versions of the generic functional interfaces built specifically for int, long, and double. They exist purely for performance: using a generic Function<Integer, R> would autobox every int into an Integer object, creating unnecessary object overhead in hot loops, whereas IntFunction<R> operates directly on the primitive with no boxing.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response