I have a map-like type SmurfMap<K, V>
which in certain contexts I use as a set-like SmurfMap<K, Void>
. Implementation details forbid the values of the map from being null
, so I cannot actually use Void
as a unit type. Are there any non-null alternatives to Void
in the JCL or Guava?
Types considered and not yet rejected:
- new singleton enum
Unit
Class<Void>
TypeToken<Void>
Object
EDIT SmurfMap<K, V>
does not implement java.util.Map
. The datastructure backing a SmurfMap
is terabytes to petabytes in size.
Set<T> set = Collections.newSetFromMap(Map<T, Boolean> map)
)"fish"
and a map where the key"fish"
go tofalse
?java.util
, don't blame me for quirky stuff there!SmurfMap
, which doesn't implementjava.util.Map
and therefore nokeySet()
to rely on? FWIWjava.util.HashSet
is backed byjava.util.HashMap
and usesprivate static final Object PRESENT = new Object();
as the value.