Best Practices for extending utility classes in java

Viewed 2823

I've extended classes from apache-commons-3 to add my own utility functions which are unavailable in them. e.g.:

public class CollectionUtils extends org.apache.commons.collections.CollectionUtils
{
        /**
     * Similar to collection.contains(member) except just doesn't throw NPE when set is null, simply returns false
     * @param collection
     * @param member
     * @return
     */
    public static <K> boolean contains(Collection<K> collection,K member)
    {
        return collection!=null && collection.contains(member);
    }
}

This solved my purpose of using my functions & commons functions through same class CollectionUtils.

But, Apache has removed extendibility in version 4 by introducing private constructors in the utility classes. There is also a discussion on the same here.

Now, my code is breaking if I upgrade to version 4. What are the best practices to extend utility classes to add custom/specific utility methods?

1 Answers
Related