Skip to content

Instantly share code, notes, and snippets.

@yinonavraham
yinonavraham / AB.java
Created February 21, 2017 21:22
Part of the following post in orange-coding.blogspot.com: Enhancing (extending) a class using dynamic proxy classes in Java
public interface AB extends A {
String bar();
}
@yinonavraham
yinonavraham / A.java
Last active February 21, 2017 21:24
Part of the following post in orange-coding.blogspot.com: Enhancing (extending) a class using dynamic proxy classes in Java
public interface A {
String foo();
}
@yinonavraham
yinonavraham / ABFactory.java
Last active February 20, 2017 09:54
Part of the following post in orange-coding.blogspot.com: Enhancing (extending) a class using dynamic proxy classes in Java
public abstract class ABFactory {
private ABFactory() { /* prevent instantiation */ }
public static AB createAB(A a) {
B b = new BImpl(a);
return (AB) Proxy.newProxyInstance(a.getClass().getClassLoader(),
new Class[]{AB.class}, (proxy, method, args) -> {
Class<?>[] declaringClassInterfaces = method.getDeclaringClass().getInterfaces();
List<Class<?>> interfaces = new ArrayList<>(Arrays.asList(declaringClassInterfaces));
interfaces.add(method.getDeclaringClass());
GET /trust/official.json HTTP/1.1
Host: dvjy3tqbc323p.cloudfront.net
User-Agent: Go 1.1 package http
Accept-Encoding: gzip