![]() ![]() These functions are used along with primitive specialized versions of streams such as IntStream, DoubleStream, and LongStream. ![]() For example, there is an IntFunction, a DoubleFunction, and a LongFunction, which are int, double, and long, versions of Function. package contains int, double, and long (but no float) versions of all the functional interfaces. One more thing to note is that none of the primitive specialized functional interfaces (such as IntFunction, DoubleFunction, or IntConsumer) extend the non-primitive functional interfaces (i.e. IntFunction, IntConsumer, IntSupplier, etc.) to achieve better performance. IntStream, LongStream, and DoubleStream) and primitive specialized functional interfaces (i.e. Thus, whenever you want to process streams of primitive elements, you should use the primitive specialized streams (i.e. This will avoid auto-boxing/unboxing altogether. You can now process each element of the stream using IntFunction. For example, instead of using Stream, you should use IntStream. To eliminate this problem, the function package contains primitive specialized versions of streams as well as functional interfaces. Stream and Function), you will incur the cost of boxing and unboxing the elements. ![]() Thus, if you have a stream of primitive ints and if you try to use the object versions of Stream and Function (i.e. They are made compatible through the extra step of auto-boxing/unboxing. int and Integer, double and Double, etc.) are not really compatible with each other in Java. The primitive and object versions of data types (i.e. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |