Skip to content

Instantly share code, notes, and snippets.

@sureshsarda
Created December 23, 2022 11:46
Show Gist options
  • Save sureshsarda/7411796686f44eb5cd3d56e35e93c2f0 to your computer and use it in GitHub Desktop.
Save sureshsarda/7411796686f44eb5cd3d56e35e93c2f0 to your computer and use it in GitHub Desktop.
A example using Proxy.newProxyInstance in Java
public class Application {
private interface Interface1 {
void method1();
}
private interface Interface2 {
void method2();
}
public static void main(String[] args) {
Object o = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{Interface1.class, Interface2.class}, (proxy, method, args1) -> {
System.out.println(method.getDeclaringClass());
System.out.println(method.getName());
return null;
});
((Interface1) o).method1();
((Interface2) o).method2();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment