First of all, it is not always a good idea to make a protective copy. You only want to do this with mutable classes that cannot enforce the contract that your business logic requires (such as collections).
Your perfect example. FilenameFilter is immutable - nothing can change it through this interface. Feel free to transfer it as you wish. The only potential problem is threads, and this is a pretty rare problem.
A more general solution (for classes that are actually a problem similar to collections) would be to wrap the collection in the class, rather than copying it. If you put it in a business logic class, you can restrict access until you make sure that it does not violate your business logic rules, and then feel free to pass it around.
You will notice that the JDK almost never misses collections. This is intentional, and the exact reason for the "Copy" template that you are considering. Typically, the JDK passes an array, and most collections have a fairly simple way to generate copies of their contents for transfer.
Copying an object is actually extremely rare - collections and arrays are primary. Most other objects can protect themselves quite well, even if they are designed with half sticking.
source share