public class X { void f(Object action) { if (action instanceof Runnable) { Runnable runnable = (Runnable)action; } } }