Most readable solution is using Static Import. Then you will not need to use AnotherClass.constant
.
Write a class with the constant as public static
field.
package ConstantPackage;
public class Constant {
public static int PROTEINS = 1;
}
Then just use Static Import where you need the constant.
import static ConstantPackage.Constant.PROTEINS;
public class StaticImportDemo {
public static void main(String[]args) {
int[] myArray = new int[5];
myArray[PROTEINS] = 0;
}
}
To know more about Static Import please see this stack overflow question.