Created
December 23, 2022 11:46
-
-
Save sureshsarda/7411796686f44eb5cd3d56e35e93c2f0 to your computer and use it in GitHub Desktop.
A example using Proxy.newProxyInstance in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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