2

I was wondering how I would access a Class variable from within a method where I have gotten the Class as an argument. Like this:

Method

public void someMethod(Class<? extends SomeClass> clazz) {
     System.out.println(clazz.var);
}

Class

class SomeClass {
    public static String var = "Hello World!";
}

The part class.var doesn't work as expected. If an extending Class changes the value of var I want this value to be written out instead.

EDIT: This question is not answered by this question. I need to access a class variable not a private one.

Ivar Eriksson
  • 863
  • 1
  • 15
  • 30

0 Answers0