When you call a var argument method, Java creates an array for your arguments, which might be considered wasteful in some use cases (like in a loop). Providing APIs with "unrolled" arguments avoids this creating and filling this array.
Gary On Mon, Sep 6, 2021, 08:51 jingguo yao <[email protected]> wrote: > org.apache.logging.log4j.Logger has the following info method with the > message parameter count from 0 to 10. > > void info(String message) > void info(String message, Object p0) > void info(String message, Object p0, Object p1) > ... > void info(String message, Object p0, Object p1, Object p2, Object p3, > Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) > > And it also has the following varargs info method: > > void info(String message, Object... params) > > With all the above methods available, only if the message parameter count > is more than 10, varargs info method will be used. > > What is the reason to have all these info methods? Is it that varargs' has > a negative impact on performance? > > Here is some discussion about varargs' performance on Stackoverflow: > > > 1. https://stackoverflow.com/a/63121156/431698 > 2. https://stackoverflow.com/a/69074193/431698 (I posted this answer) > > > -- > Jingguo >
