Thu. Apr 18th, 2024
Keeping Containers Safe

Sometimes you need to guarantee a list is safe to use. A simple method can make sure your safe to use the list, or have an empty list that would be safe for use.

/**
     *  Guarantees a list will be safe to use, even if null.
     * @param list List to check if null
     * @param <E> List Type
     * @return List, or an empty list of E.
     */
    public static <E> List<E> safe(List<E> list) {
        if(list != null) {
            return list;
        }
        
        return Collections.emptyList();
    }

A simple method to use to make sure your variables are safe. To see all of ListUtils.

By Jeffery Miller

I am known for being able to quickly decipher difficult problems to assist development teams in producing a solution. I have been called upon to be the Team Lead for multiple large-scale projects. I have a keen interest in learning new technologies, always ready for a new challenge.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.