mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 06:15:41 +00:00
Added a caching mechanism to AnnotationValues, for instantiating the annotation.
This commit is contained in:
1 parent
47bd3e3c06
commit
157bbba3ac
1 file changed
+4
-1
@@ -77,8 +77,11 @@ public class AnnotationValues<A extends Annotation> {
|
||||
"No value supplied but " + method.getName() + " has no default either.", -1);
|
||||
}
|
||||
|
||||
private A cachedInstance = null;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public A getInstance() throws AnnotationValueDecodeFail {
|
||||
if ( cachedInstance != null ) return cachedInstance;
|
||||
InvocationHandler invocations = new InvocationHandler() {
|
||||
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
AnnotationValue v = values.get(method.getName());
|
||||
@@ -134,7 +137,7 @@ public class AnnotationValues<A extends Annotation> {
|
||||
}
|
||||
};
|
||||
|
||||
return (A) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, invocations);
|
||||
return cachedInstance = (A) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, invocations);
|
||||
}
|
||||
|
||||
private Object guessToType(Object guess, Class<?> expected, AnnotationValue v, int pos) {
|
||||
|
||||
Reference in new issue
Block a user