I am trying to see why declaring static final variable is NOT enough for singleton pattern.
For that I have created following 3 classes:
Running this code results in following exception.
Exception in thread "Thread-620" java.lang.ClassCastException: SingletonCheck cannot be cast to java.lang.Comparable
Could someone help me in solving this error please?
Do I need to implement equals() method?
posted 8 years ago
Changing from ConcurrentSkipListSet to CopyOnWriteArraySet did the trick. Need to see why it's failing for ConcurrentSkipListSet.
Well, the error message should be making that pretty clear, and you can confirm this by going to the Javadocs: objects put into a ConcurrentSkipListSet have to implement Comparable. TreeMap, TreeSet, and other sorted collections are the same way. You can generally supply a Comparator instance instead, if your class doesn't want to implement Comparable.