Reputation: 757
I am trying to instrument a class file, but I was just wondering where annotations are stored in the class file format. I tried putting them in the interface table however, when I did that it only recognized them as an interface not as an annotation.
Upvotes: 4
Views: 2657
Reputation: 25623
They are stored in the RuntimeVisibleAnnotations
and RuntimeInvisibleAnnotations
attributes for classes and methods class members, and the RuntimeVisibleParameterAnnotations
and RuntimeInvisibleParameterAnnotations
attributes for method parameters. You can find more detailed information about the classfile format in the Java VM Specification.
Upvotes: 5
Reputation: 5018
When trying to understand Java bytecode, a good starting point is writing in plain Java the class you would like to create using bytecode. Compile it, then use tools to retrieve generated bytecode.
Here's some tools I can think of :
main
method to make it easy to run)Show bytecode
viewUpvotes: 0