class X { void foo(Object o){ if (o instanceof Foo) { ((Foo) o).bar(); } } class Foo { void bar() {} } }