Is there any way to make a reference variable to the name of a class?
For example, let's say we have these two classes
class ClassA {
public static String s = "This is class A";
}
class ClassB {
public static String s = "This is class B";
}
and then we want to use them like this
// first somehow give the name of ClassA to some variable MyRef
// then print "This is class A"
System.out.print(MyRef.s);
// then give the name of ClassB to the same variable MyRef
// and then print "This is class B"
System.out.print(MyRef.s);
Is there any way to do this? If not, is there any other simple way to do the same thing, that is, to easily switch between the static variables of ClassA and the static variables of ClassB?
ClassA.class.getName()