There are two ways to use a CopyOnWriteArraySet:// ASet<Object> set = new CopyOnWriteArraySet<>();and// BCopyOnWriteArraySet<Object> set = new CopyOnWriteArraySet<>();With 'normal' sets like HashSet and TreeSet, case A is preferred, because it allows easy switching of the Set implementation.However, in this case a conscious choice is made for a specific thread-safe Set implementation. Should I use case B to signify this intent?
Should I reference a CopyOnWriteArraySet from the Set interface?
java;design;multithreading
You can deliberately declare a more specific type to document your threading policy. However, a functioning threading policy requires much more than judiciously chosen types, so it doesn't add that much value.In your example, you are invoking the constructor of the concrete class in the very same line, so the choice would have been obvious even anyway. It would be more worthwhile to use types for communicating if your set were returned to an external user, e.g. via an interface or a method return type. 