void (String[] args) { Runnable myProxy = (Runnable) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{Runnable.class}, (proxy, method, params) -> { if (method.getName().equals("run")) { System.out.println("Hello World!"); } return <warning descr="Null might be returned when proxying method 'equals()': this may cause NullPointerException">null</warning>; }); myProxy.run(); HashSet<Runnable> set = new HashSet<>(); set.add(myProxy); }