Java: Treemap - forbid null?

java, null, treemap

Solution

Write up a delegating Set that wraps the real Set and add a guard to Set.add().

If you are providing a Comparator to the TreeSet you can also complain if either of thw two inputs to the Comparator are null.

Problem

Is there a way to prevent a treemap from accepting null values, or do I need to do a check every time I enter something?

Original source