I have an inner class that stores the info of the controls I'm using for a game, now I want to store a static ArrayList in it that holds all the names of the controls. But I am getting this error: "Modifier static is only allowed in constant variable declarations"
private class Control{
public ArrayList<String> keys = new ArrayList<String>();
public final String key;
public final Trigger trigger;
Control(String k, Trigger t){
key = k;
trigger = t;
keys.add(key);
}
}
Now I know this can easily be solved by taking the ArrayList out of the class and storing it in the main class. But I'd prefer to keep all the information in one class where I can access everything.
"Control.key, Control.trigger, Control.keys" is just more elegant/readable than "key, trigger, keys"
Or maybe I just have Obsessive–compulsive disorder, still I'd like to do it my way.
Make your inner class static and it will work:
You can make the
Control
class static.This is described in the Java Language Specification Section §8.1.3