public class A {
static class B {
}
}
public class C {
void m(X x) {
if (x instanceof A.B) { ... } // not working
}
}
Is there a way to verify if some object (x) is actually the inner class (B) of some class (A) in this scenario?
I’m getting this error, but I unfortunately have no control over the classes A and B.
The type A.B is not visible
I made this answer as a comment, but with a little reflection (the thinking kind, not the coding kind!), I’m turning it into an answer.
Since you don’t have control over A or B, and B has package access, you can only see it from classes that are in the same package as A. So what you could do – if you don’t want to move C into the same package – is write a utility class – call it U – that has a boolean function, taking an X and returning whether it’s an instance of A.B.