[Solved] How might I count the number of int members defined for a Java class?


It’s just 106 “public final static int int1 = int1value” in the first class. No List or Arrays.

How lame!

Unfortunately there is no neat way to sum the values of a large number of statics. You could do it using reflection (see @BalusC’s answer), or simply by writing a method evaluates hard-wired expressions like:

public static int calculateSum() {
    return int1 + int2 + 
           // and so on
           + int160;
}

public static int calculateCount() {
    return 160;
}

Your real problem is in your program design. The use of statics is dubious, the use of 160 named variables (instead of an array or list) is bad, and even putting the method(s) in a separate class is dubious.

Fix the design problems and you don’t have this one.

solved How might I count the number of int members defined for a Java class?