Consider this Java code
class A{
//@returns Class object this method is contained in
// should be A in this case
public Class<?> f() {
return getClass();
}
}
class B extends A {}
B b = new B();
System.out.println(b.f());
//output -- B.class (Wrong, should be A.class)
inside f()
i can't use getClass()
because that will give me the runtype, which is B
. I'm looking for a way to get the Class
object of the class
f()
is inside (Without mentioning A
explicitly, obviously)