The problem is that your two Inside
types are currently unrelated - there's no way for X.doSomeWork()
to do refer to "it's this type or that type" when they're entirely different types. The fact that they're both nested classes called Inside
doesn't make any difference.
If you extract the common behaviour (that X
wants to call) into an interface and make both Inside
classes implement that interface, then you can use that commonality. Basically do exactly what you'd do if they weren't nested classes and didn't have the same name, because X
doesn't care about either of those aspects.