This is a performance hit.
I would not worry about the "hit of productivity". Creating objects in Java is very fast. The difference in performance is unlikely to be measurable.
In any case, use the size if you know it. If you don’t do it, there’s nothing to be done.
The kind of thinking you are doing here is called "premature optimization." Donald Knuth says this is the root of all evil.
Better to get your code working before doing it fast. Optimize the data that tells you where your code is slow. Do not guess - you are probably mistaken. You will find that you rarely know where the bottlenecks are.
source share