5 ms·
I don't think I have seen classes with many parameters to avoid varargs in Java, however I have certainly seen classes with dozens of Type Parameters, I believe
by paradaux 5y ago
I don't think I have seen classes with many parameters to avoid varargs in Java, however I have certainly seen classes with dozens of Type Parameters, I believe some form of code generation was responsible.
Can't for the life of me find that class again.
- jdmichal 5y agoSLF4J Loggers define up to two arguments for precisely this purpose: https://www.slf4j.org/apidocs/org/slf4j/Logger.html#error(java.lang.String,java.lang.Object https://www.slf4j.org/apidocs/org/slf4j/Logger.html#error(ja......) > This form avoids superfluous string concatenation when the logger is disabled for the ERROR level. However, this variant incurs the hidden (and relatively small) cost of creating an Object[] before invoking the method, even if this logger is disabled for ERROR. The variants taking one and two arguments exist solely in order to avoid this hidden cost.
- vips7L 5y agoLook at Set.of and Map.of. Lots of overloads to avoid allocating the vararg array.