The following code throws an unexpected ClassCastException when a value is found, i.e. the default value is not used:
final Collection<String> myCollection = myDocument.get("myKey", Collections.emptySet()); // throws: java.lang.ClassCastException: Cannot cast java.util.Collections$UnmodifiableSet to java.util.Collections$EmptySet
The following complicated code works:
final Collection<String> myCollection = document.get("myKey", Collections.unmodifiableSet(Collections.emptySet()))
In my opinion, this method is useless (and dangerous) in the public API. If you want to provide such a functionality, you should consider to provide a method which also requires the class to cast to: Document#get(Object key, Class<T> clazz, T defaultValue)
This method should cast to clazz instead of the defaultValue.getClass().