Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.*;
- interface Foo {}
- interface Bar {}
- class FooBar1 implements Foo, Bar {public String toString() { return "FooBar1"; }}
- class FooBar2 implements Foo, Bar {public String toString() { return "FooBar2"; }}
- class FooBar {
- static <T extends Foo & Bar> T getFooBar1() { return (T) new FooBar1(); }
- static <T extends Foo & Bar> T getFooBar2() { return (T) new FooBar2(); }
- static <T extends Foo & Bar> T getFooBar() {
- return (T)
- Proxy.newProxyInstance(
- Foo.class.getClassLoader(),
- new Class[] { Foo.class, Bar.class },
- new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args) {
- return "PROXY!!!";}});
- }
- static <U extends Foo & Bar> void show(U u) { System.out.println(u); }
- public static void main(String[] args) {
- show(getFooBar());
- show(getFooBar1());
- show(getFooBar2());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement