2
메서드 위임을 구현하고 모든 세터를 위임하여 클래스의 더티 필드를 추적하는 필드를 추가하려고합니다. 나는 세터에 호출되고있는 "개체"를 얻을 수 없습니다있어, 위임,메서드 위임 및 필드 추가
@RuntimeType
public static Object intercept(@SuperCall Callable<?> superMethod, @Origin Method method, @Super(proxyType = TargetType.class) Object delegate) throws Exception {
System.out.println ("---- Intercept");
markDirty (delegate, Character.toLowerCase (method.getName().charAt(3)) + method.getName().substring(4));
return superMethod.call();
}
을하지만 :
T t = new ByteBuddy()
.subclass (typeClass)
.defineField ("dirtyFields", List.class, Visibility.PUBLIC)
.method(ElementMatchers.isSetter())
.intercept(MethodDelegation.to(SetterInterceptor.class))
.make()
.load (SetterInterceptor.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded()
.newInstance();
List<String> l = new ArrayList<String>();
t.getClass().getField("dirtyFields").set(t, l);
l.add("foobar");
return t;
내 인터셉터는 다음과 같습니다 : 내 클래스의 인스턴스는 다음과 같습니다 그 객체를 참조하지 않는 것 같습니다. 이 기능을 제공하기 위해 내가해야 할 일이 있는지 또는 내가 주입 할 수있는 것이 있는지 궁금합니다.
감사합니다. 당신이 오히려 비싼 대상 클래스에`Super` @ 프록시를 사용하지 않아야합니다
public static Object intercept(@This Object thiz, @SuperCall Callable<?> superMethod, @Origin Method method, @Super(proxyType = TargetType.class) Object delegate) throws Exception {
참고 : –