Java logger allows the following syntax:
m_logger.info("ID: {} NAME: {}", id, name); // 1
m_logger.info("ID: " + id + " NAME: " + name); // 2
In the first case, essentially we are calling the ... function and thus a new Object[]
is created every time.
I ran through YourKit and that's what I see.
My question is that isn't the 1st case an expensive operation that we should be avoiding all the time? But yet I have seen this in a lot of codes. What are we gaining by using #1?
And I suppose we should use StringBuilder
for best performance?