【发布时间】:2025-12-27 23:00:17
【问题描述】:
我想使用 void java 的类型,但我不能。这是我的代码,它是在所有具有@TraceLog 注释的方法之后运行的方面
@AfterReturning(value = "@annotation(log)",
returning = "returnValue",
argNames = "joinPoint, log, returnValue"
)
public void afterReturning(final JoinPoint joinPoint, final TraceLog log,
final Object returnValue) {
Class<?> returnType = ((MethodSignature) joinPoint.getSignature())
.getReturnType();
//It works when comperaing with string. But I want to write it with type of
if ("void".equals(returnType.getName()) ) {
//Do some log
}
}
作为编码规则类不应按名称比较(http://cwe.mitre.org/data/definitions/486.html),我尝试使用(returnType instanceof Void)但在eclipse中遇到这两个编译时错误:
- Incompatible conditional operand types Class<capture#5-of ?> and Void
- The type Void is not generic; it cannot be parameterized with arguments <?>
我想知道我该如何解决它?!
【问题讨论】: