If you read the source code of SpringAOP, [this kind of code](http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-aop/4.2.0.RELEASE/org/springframework/ There was aop / aspectj / AspectJExpressionPointcut.java # AspectJExpressionPointcut) (code adjusted to remove noise).
AspectJExpressionPointcut.java
public class AspectJExpressionPointcut {
private static final Set<PointcutPrimitive> SUPPORTED_PRIMITIVES = new HashSet();
static {
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.EXECUTION);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.ARGS);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.REFERENCE);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.THIS);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.TARGET);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.WITHIN);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ANNOTATION);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_WITHIN);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ARGS);
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_TARGET);
logger = LogFactory.getLog(AspectJExpressionPointcut.class);
}
}
This is a mechanism called Static Initialization Block. Until now, the initialization of List / Set etc. declared as static was written as ↓, but I feel that the static initialization block looks cleaner.
public class Hoge {
private static final Set<PointcutPrimitive> SUPPORTED_PRIMITIVES = new HashSet(){{
add(PointcutPrimitive.EXECUTION);
add(PointcutPrimitive.ARGS);
add(PointcutPrimitive.REFERENCE);
add(PointcutPrimitive.THIS);
add(PointcutPrimitive.TARGET);
add(PointcutPrimitive.WITHIN);
add(PointcutPrimitive.AT_ANNOTATION);
add(PointcutPrimitive.AT_WITHIN);
add(PointcutPrimitive.AT_ARGS);
add(PointcutPrimitive.AT_TARGET);
}};
}
Recommended Posts