Enforce singleton pattern in CaseInsensitiveComparator
Make sure that new instances of CaseInsensitiveComparator are not created when serializing/deserializing.
@@ -40,5 +40,12 @@ public final class CaseInsensitiveComparator implements Comparator<String>, Seri
return lhs.compareToIgnoreCase(rhs);
}
+ /**
+ * Enforce singleton pattern when serializing/deserializing
+ */
+ private Object readResolve() {
+ return INSTANCE;
+ }
+
private static final long serialVersionUID = 1L;
}
