Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how is java annotation represented in java bytecode

I tried to decompile a .class file that contains JUnit tests. I read the byte code, but I did not see any clue of the @Test annotation(it's used in the java source code).

As metadata, how are annotations represented in bytecode?

like image 271
Cui Pengfei 崔鹏飞 Avatar asked Sep 11 '12 10:09

Cui Pengfei 崔鹏飞


People also ask

How does bytecode look like in Java?

class files consist of a bunch of bytecodes. Bytecode is to Java what assembler is to C++. Each bytecode is a number no larger than a byte and has a mnemonic. The numbers and their mnemonic are what you have listed in your question.

What is the format of bytecode in Java?

The bytecode formatBytecodes are the machine language of the Java virtual machine. When a JVM loads a class file, it gets one stream of bytecodes for each method in the class. The bytecodes streams are stored in the method area of the JVM.

How are annotations executed in Java?

Annotations don't execute; they're notes or markers that are read by various tools. Some are read by your compiler, like @Override ; others are embedded in the class files and read by tools like Hibernate at runtime.


1 Answers

Annotations appear just before the byte code of the thing it is associated with. If you are not seeing the annotations it could be an old de-compiler (most of them are)

like image 190
Peter Lawrey Avatar answered Dec 02 '22 04:12

Peter Lawrey