79098440

Date: 2024-10-17 14:06:21
Score: 1.5
Natty:
Report link

Technically the function List.of(E... elements) can take care of any number of input elements. However, the input can be an array, and the caller has the reference to the input array. The caller could update the array while the immutable list is being constructed, causing inconsistency. That is referred to as Time-of-Check to Time-of-Use (TOCTOU). To avoid TOCTOC, Java must make a copy of the input array, which has performance penalty. The overloaded functions with specific number of input arguments do not have TOCTOU issue, no copying is needed thus better performance.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: Jeffrey