This is a silly question, but here it goes.
I have a multithreaded program and a “global” Collection of unique elements. I rejected synchronized Set implementations due to performance, for the ConcurrentHashMap. I don’t really need the Value part of Map, so I wanted to use the smallest Object in java in terms of memory usage. I solved this issue in a different way (single Boolean object referenced multiple times in the Map), but I am still curious what is the smallest object in Java. I always thought it to be Boolean, but that is not true I think (Java – boolean primitive type – size, Primitive Data Types)
It doesn’t really matter, actually, since the value part of each association is fixed to be a reference. You might even use
nullas value here, but any other (fixed) object reference should be fine (and more convenient sometimes). I’d preferBoolean.TRUE(or a similar “well known” singleton). You can then test for membership viain addition to