Using wild cards with static classes in java
<p>The idea I'm going for is that I have a bunch of actions/functions that happen in our program.  They're all predefined and separated into categories.  So there might be a category for admin actions that then defines a bunch of static codes for actions that are in the admin actions category.</p>

<p>Since the categories and actions are fixed, they're all in static classes.</p>

<p>These static category classes all implement an interface, ICategory:</p>

<pre><code>public static interface ICategory{
    int getCateogory();
    String getCategoryName();
    String getFunctionName(int function);
}
</code></pre>

<p>Each of these static classes is added to a static Map:  </p>

<pre><code>private static Map&lt;Integer, Class&lt;? extends ICategory&gt;&gt; catMap = new HashMap&lt;Integer, Class&lt;? extends ICategory&gt;&gt;();
</code></pre>

<p>Basically there's an integer code associated with each category. What I'm trying to do is just made a human readable string that I can print out when I receive the category and action codes. What I would like to do is something like </p>

<pre><code>ICategory whatever = catMap.get(catNumber);
System.out.println(whatever.getCategoryName());
System.out.println(whatever.getFunctionName(actionCode));
</code></pre>

<p>So catMap.get(catNumber) will actually return the proper static class, but I then don't know how I can use that returned class to access these static methods.  I can do it with regular instances of a class, just fine, but doing it with static classes has got me puzzled.</p>

<h2>Clarification of Problem:</h2>

<p>Some Clarification of The problem I'm trying to solve in case you guys have suggestions of better / more intuitive ways to do this:</p>

<p>Basically I'm interpreting commands from some piece of custom hardware at my company.  It's a little data collection gizmo that has a bunch of predefined messages/functions that I have to interpret.</p>

<p>These functions are split into various categories: Display, Keypad, Acquisition, etc.</p>

<p>So basically I have a mapping like this:</p>

<pre><code>  Display Category: 128
      ShowGraph: 01
      ShowText: 02
  Keypad Category: 129
      F1: 01
      F2: 02
      MenuKey: 03
</code></pre>

<p>I'm making a little stream display that prints the stream of commands out in human readable format.  So I'd just print out a big list of something like</p>

<pre><code>Got Category Display, Function ShowGraph
Got Category Keypad, Function MenuKey
</code></pre>

<p>Normally I'd use a map for this, but what I want is to also use the functions in each category as constants because I'll have to reference them in if-statements and often times send those same categories back to the little gizmo.  </p>

<p>For Instance:</p>

<pre><code>sendMessage(Categories.DisplayCategory.getCategoryInt(), Categories.DisplayCategory.SHOW_GRAPH);
</code></pre>

<h2>More Code as requested:</h2>

<pre><code>public class Functions {

    public static interface ICategory{
        int getCateogory();
        String getCategoryName();
        String getFunctionName(int function);
    }

    private static Map&lt;Integer, Class&lt;? extends ICategory&gt;&gt; catMap = new HashMap&lt;Integer, Class&lt;? extends ICategory&gt;&gt;();

    public static String getCategoryString(int category) {
        Class&lt;? extends ICategory&gt; clazz = catMap.get(category);
        System.out.println(catMap.toString());

        if(clazz != null){
            try{
                Method m = clazz.getMethod("getCategoryName", Integer.class);
                return (String) m.invoke(0, category);
            }catch (Exception e){
                return null;
            }

        }else{
            System.out.println("clazz was null");
            return null;
        }
    }

    public static class SystemKey implements ICategory{
        public static int CATEGORY = 134;
        private static Map&lt;Integer, String&gt; fmap = new HashMap&lt;Integer, String&gt;();
        @Override
        public int getCateogory() {
            return CATEGORY;
        }

        @Override
        public String getCategoryName() {
            return "SystemKey";
        }

        @Override
        public String getFunctionName(int function) {
            return fmap.get(function);
        }
    }

    public static class SystemCat implements ICategory{
        public static int CATEGORY = 128;
        private static Map&lt;Integer, String&gt; fmap = new HashMap&lt;Integer, String&gt;();

        public static final int POWER_UP = 0x01;
        public static final int END_OF_TRANSMIT = 0x02;
        public static final int CLEAR_TO_SEND = 0x03;
        public static final int NET_TEST = 0x05; /*Fom station to ctrlr*/ 
        public static final int NET_OK = 0x06; /*Response to controller*/
        public static final int MAIN_MENU = 0x07;

        static{
            catMap.put(CATEGORY, SystemCat.class);

            fmap.put(POWER_UP, "POWER_UP"); 
            fmap.put(END_OF_TRANSMIT, "END_OF_TRANSMIT"); 
            fmap.put(CLEAR_TO_SEND, "CLEAR_TO_SEND");
            fmap.put(NET_TEST, "NET_TEST"); 
            fmap.put(NET_OK, "NET_OK"); 
            fmap.put(MAIN_MENU, "MAIN_MENU");
        }


        @Override
        public int getCateogory() {
            return CATEGORY;
        }

        @Override
        public String getCategoryName() {
            return "System";
        }

        @Override
        public String getFunctionName(int function) {
            return fmap.get(function);
        }
    }




    public static class SoftKey implements ICategory{
        public static int CATEGORY = 129;

        private static Map&lt;Integer, String&gt; fmap = new HashMap&lt;Integer, String&gt;();

        public static final int F1 = 0x20;
        public static final int F2 = 0x21;
        public static final int F3 = 0x22;
        public static final int F4 = 0x23;
        public static final int F5 = 0x24;

        static{
            catMap.put(CATEGORY, SoftKey.class);

            fmap.put(F1, "F1");
            fmap.put(F2, "F2");
            fmap.put(F3, "F3");
            fmap.put(F4, "F4");
            fmap.put(F5, "F5");

        @Override
        public int getCateogory() {
            return CATEGORY;
        }

        @Override
        public String getCategoryName() {
            return "SoftKey";
        }

        @Override
        public String getFunctionName(int function) {
            return fmap.get(function);
        }

    }


    public static void main (String[] args) throws Exception{


         System.out.println(Functions.getCategoryString(128));
    }

}
</code></pre>
