다른 ByteBuddy 코드를보고 있습니다. 그는 ByteBuddy를 사용하여 런타임의 특정 관리 코드를 특정 객체에 구현하기 위해 프록시로 사용되는 런타임 하위 클래스를 생성합니다. I 이렇게 I은 생성 된 클래스를 재사용 (및 기능의 모든 호출을 위해 재생성되지 않음) 할 수있는 새로운 정의 필드 _core
을 사용할 람다에 직접 core
객체 결합하지 위해서는ByteBuddy : 클래스 생성시 절편에서 새 정의 필드 사용
Class<? extends T> newSubClass = new ByteBuddy(ClassFileVersion.ofThisVm())
.subclass(classType)
.defineField("_core", Object.class, Visibility.PUBLIC) //<---
.method(ElementMatchers.isDeclaredBy(classType))
.intercept(InvocationHandlerAdapter.of((proxy, method, m_args) -> {
//TODO: Need to replace core with _core as core is a function argument and will make it bound
return proxyHandler(core, method, m_args); //<--
}))
.make()
.load(roleType.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
T proxy = ReflectionHelper.newInstance(newSubClass, args);
newSubClass.getField("_core").set(proxy, core);
. 이 방법이 있습니까?
미리 감사드립니다.
힌트 w.r.t을 주셔서 감사합니다. 캐싱. 나는'WeakHashMap, Class >>'else를 사용했을 것이다. –
lschuetze
값이 키의 하위 클래스이며이를 강력하게 참조하므로 작동하지 않습니다. 오히려 값을 부드럽게 또는 약하게 참조함으로써이 문제를 해결하는'TypeCache'를 사용하십시오. –
'.intercept (InvokeHandlerAdapter.of ((proxy, method, m_args) -> proxyHandler (core, method, m_args);)의 새로운'_core' 인자에 접근 할 수있는 방법이 아직도 명확하지 않습니다. – lschuetze