I thought that null
is allowed for a Set
.
So why does the following code:
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(null);
set.add(1); //--->Line indicated by exception
Gives the following exception?
Exception in thread "main" java.lang.NullPointerException at
java.lang.Integer.compareTo(Unknown Source) at
java.lang.Integer.compareTo(Unknown Source) at
java.util.TreeMap.put(Unknown Source) at
java.util.TreeSet.add(Unknown Source)