This content has been marked as final.
Show 2 replies
-
1. Re: Help on class anotation
theyurinator Aug 13, 2008 1:28 PM (in response to theyurinator)To be a little more specific, this is the exact code I have
public static void main(String[] args) { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.makeClass("sample"); ClassFile cf = cc.getClassFile(); ConstPool cp = cf.getConstPool(); AnnotationsAttribute attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag); Annotation a = new Annotation("Author", cp); a.addMemberValue("name", new StringMemberValue("Chiba", cp)); attr.setAnnotation(a); cf.addAttribute(attr); cf.setVersionToJava5(); try { cc.writeFile(); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CannotCompileException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
and this is what I see with javap as a result.public class sample extends java.lang.Object{ public sample(); }
I don't really understand what I am doing wrong? If I step through with the debugger, I do see the AnnotationsAttribute added to the ClassFile object, and the Annotation object is added to the AnnotationsAttribute object. -
2. Re: Help on class anotation
theyurinator Aug 13, 2008 2:42 PM (in response to theyurinator)Please ignore this topic, I have realized that javap does not printout annotations unless I put the -verbose flag on.