I feel like I'm missing something blindingly obvious here, so low hanging fruit for a Java guru:
I have code that looks like this:
private static void myFunc(JComponent c) {
if (c instanceof JPanel) {
//stuff
}
else if (c instanceof JMenu) {
// other stuff
}
}
Even though JPanel and JMenu are both subclasses of JComponent, the first instanceof
gives an error:
Incompatible conditional operand types JComponent and JPanel
While the second one works fine. Why does it think that my JComponent
could never be a JPanel
?