Switch statement and initializing a final static variable in static block-Collection of common programming errors

For my project, I have many objects split into 10 classes. Each of the objects may perform some operations, which have to be registered beforehand (the registering of operations is done only once per class). The operations defined for each class are represented as public final static integers. I would like to dynamically assign the ID of operations at runtime (the number of operations per class is currently about 20 and the number will increase).

The problem arises, when an operation is performed and I have to find which operation is being performed (I use a switch statement).

Here is a simple example of working code:

public class Test {
    final static int foo = 8;
    final static int bar = 10;

    public static void main(String[] args)
    {
        int x=10;

        switch(x)
        {
        case foo:
            System.out.println("FOO");
            break;
        case bar:
            System.out.println("BAR");
            break;
        default:
            System.out.println("PROBLEM");
        }
    }
}

This code normally compiles and displays BAR.

But this slightly transformed code produces an Unresolved compilation problem with case expressions must be constant expressions.

public class Test {
    final static int foo;
    final static int bar;

    static
    {
        foo=8;
        bar=10;
    }
    public static void main(String[] args)
    {
        int x=10;

        switch(x)
        {
        case foo:
            System.out.println("FOO");
            break;
        case bar:
            System.out.println("BAR");
            break;
        default:
            System.out.println("PROBLEM");
        }
    }
}

Shouldn’t these codes actually work and compile the same? I am not able to do anything dynamically until I resolve this problem? Or is any other way?

Thanks

EDIT: Due to ideas for using enums I would like to solve this problem:

public class Test {
  enum OperationSet1 {
    FOO, BAR, THESE, ARE, ALL, DIFFERENT, OPERATIONS
  }
  enum OperationSet2 {
    FOO, BAR, NOW, SOME, OTHER, OPS
  }

  public static void main(String[] args) {
    OperationSet1[] ops = new OperationSet1[10];
    for (int i=0; i