I have the following situation (I know it doesn't sound real but I simplified it for better understanding):
- A
class A
, with apublic static int f;
declared - Other classes
B, C, D, ...
that extend A - A method
foo
(somewhere else, doesn't matter) with the following signature:int foo(Class< A> classz);
Now I want this method implementation to return the value if the static field f
, from the class represented by classz
; subclasses of A
may have different values. I don't want to use reflection (and neither the new jdk7 invoke.* features). For now, I have this solution that works, but isn't good, since it instanciates an object (which should not be necessary) and it generate a warning by accessing a static field from an instance:
int foo(Class< A> classz) throws [don't matter] {
return classz.newInstance().f;
}
Any suggestions? Thanks in advance?
PS: Don't know how to type Class< ?>
without the space...