Detecting available List operations I'm writing some code which needs to take a generic java.util.List from another source and adapt to the available functions; eg. does it support add(), set(), etc.

I'm currently just calling the functions on the list and creating a set of available operations, but I'm wondering if there's a better way than try-catch.

Current code: 

import java.util.*;

import javax.swing.JPanel;

public class JListPanel&lt;T&gt; extends JPanel {
    private static final long serialVersionUID = 832057842976869638L;

    private static enum JLPFlag {
        ADD, REMOVE, SET;
    }

    private List&lt;T&gt; list;
    private Set&lt;JLPFlag&gt; flags = EnumSet.allOf(JLPFlag.class);

    public JListPanel(List&lt;T&gt; backinglist) {
        list = backinglist;
        setFlags();
    }

    private void setFlags() {
        // store the last state
        List&lt;T&gt; prev = Collections.unmodifiableList(list);
        boolean empty = list.isEmpty();
        try {
            if (!empty) {
                list.add(list.get(0));
            } else {
                // hope that list allows null
                list.add(null);
            }
        } catch (Exception e) {
            flags.remove(JLPFlag.ADD);
        }
        try {
            list.set(0, list.get(0));
        } catch (Exception e) {
            flags.remove(JLPFlag.SET);
        }
        try {
            list.remove(0);
        } catch (Exception e) {
            flags.remove(JLPFlag.REMOVE);
        }
        if (flags.contains(JLPFlag.REMOVE))
            list.removeAll(list);
        if (flags.contains(JLPFlag.ADD))
            list.addAll(prev);
    }
}


Edit: This is supposed to be a JPanel that contains a list that can be modified by a program and this should reflect those changes on the list display. It's not complete yet, but the ultimate goal is to have a list that can be modified by the user or programmer. It will have some buttons that will be disabled if the list doesn't support the operations, so it might not have add or remove but it might have set.

I've compiled most of the suggestions into this new function: http://pastebin.com/JPWXdFfi
After edit original question: 

I understand what you are trying to do, and very nice if you can do that.
That's why I'm trying to think together with you for an solution.
The only thing is that I seems not capable enough to reach to an solution.
That's why I'm still posting mine thoughts.

We have some problems(with solutions) that prevents us to check it at creation of the class : 


We init with a list, and after constructing the "wrapper" it must be the same list.
The original list may support one or more methods, add may be supported and an addAll or remove maybe not, 
Adding/removing a null can be supported or not. So if we want to test add we need a instance of T.
We can make the wrapper abstract and create an abstract T getInstance (); where we give a real instance of T or we disallow a wrapper with an empty List.This solves issue 3 but still not issue 2 when only add is supported we can't remove our T from the list. (reversed is not a problem cause it shall return false if T isn't in the list)
Maybe we could use the Object clone() what gives a shallow copy but that is in this case no problem as the copy is used to test the methods.Still a problem if it throws the CloneNotSupportedException.
We can at construction check if the CloneNotSupportedException is thrown and do the test at runtime => buttons are disabled when user press the button once or buttons are always disabled when cloning isn't possible.


Other bad solution :

Create an enum with all known implementations of List.
Check for instanceOf of the class and get the flags from the enum.

Why possible bad : 

ArrayList implements everything.
When I create a subclass of ArrayList and throw at the add an UnsupportedOperationException your check for ArrayList is good and set the flags for an ArrayList.
Still the add operation shall not work.