我需要为方法参数添加注释。该方法之前是使用 javassist 创建的,例如:
CtClass cc2 = pool.makeClass("Dummy");
CtMethod method = CtNewMethod.make("public java.lang.String dummyMethod( java.lang.String oneparam){ return null; }", cc2);
我要添加的注释非常简单:
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Param {
/** Name of the parameter */
String name() default "";
}
1) 在方法创建中写注解 throws
javassist.CannotCompileException: [source error] syntax error near "myMethod(@Param
2)找到了这个解决方案,但它基于在我的情况下返回null的行:
AttributeInfo paramAtrributeInfo = methodInfo.getAttribute(ParameterAnnotationsAttribute.visibleTag); // or inVisibleTag
我迷失了如何做到这一点;有没有人找到一种方法来创建一个新方法并为其参数添加任何注释?
提前致谢。