Skip to main content

Blog Archive for malenkov during December 2009

Caching of an empty array is a well-known pattern to improve performance. However, it is difficult to use it in generified classes. Out of curiosity, I created a custom implementation of the array creation method based on Array.newInstance. To cache empty arrays, I use synchronized WeakHashMap, which maps any given component type to a weak reference to the corresponding empty array. This is not...