I am using a TreeSet in Java to hold a list of integers:
TreeSet<Integer> num = new TreeSet<Integer>();
Since my application has multiple threads, I want to be able to access it synchronously. I'm using Collections.synchronizedSortedSet(num);
and this returns a Collections$SortedSet
. My problem is that this cannot be cast to a TreeSet
- it can only be cast to a SortedSet
. I cannot change the class of the num object, so it must be cast to a TreeSet
.
Does anyone know how I might otherwise cast Collections$SortedSet
to TreeSet
, or another method by which I could synchronize this TreeSet
?