import statement byte code significance

2019-06-15 19:49发布

Lets say , there are some import statements in a class. When the byte code is generated for that class, what happens to these import statements.

If the import statements are ignored during runtime, how are the dependencies on that classes methods resolved during runtime.

3条回答
放荡不羁爱自由
2楼-- · 2019-06-15 20:19

The purpose of import statements is just to make life easier for the human readers (and authors) of the code. Thus they are replaced by references to the fully qualified class/method names in the bytecode. And unused import statements are ignored.

查看更多
爷的心禁止访问
3楼-- · 2019-06-15 20:40

import statements are only there for the compiler so it knows what class names (or static method names) you can access unqualified in your code (i.e. MyClass instead of foo.bar.MyClass). Behind the scenes this is just used to resolve to the fully-qualified class names which are then used in the bytecode as well.

查看更多
Deceive 欺骗
4楼-- · 2019-06-15 20:44

import in Java is just a shorthand

so that if you import java.util.* you don't have to write java.util.ArrayList in your code but can write ArrayList

查看更多
登录 后发表回答