Does the Java language guarantee that the instanceof operator or the getClass() method applied to this in a constructor always applies to the deeper class in the hierarchy?
For example, if I want to limit the subclasses which are allowed to call a constructor from the superclass, I could do this:
class A {
A() {
final Class<?> clazz = getClass();
if (clazz != A.class && clazz != B.class && clazz != C.class) {
throw new IllegalStateException();
}
}
}
but I wonder whether the language guarantees that it will work or not.