I have a class with multiple subclasses:
class A {
static int i = 5;
}
class B extends A{
static int i = 6;
}
class C extends A {
static int i = 7;
}
I'm trying to write a comparator that takes two A
's and compares them based on their values of i
. I'm stuck at:
public int compare(A a1, A a2) {
}
Neither a1.i
nor a1.class.getField("i").getInt(null);
work.
How can I get the value of the static field from the object?