What happens to comments after the java files are compiled in Android?(在Android中编译java文件后的注释会发生什么?)
问题描述
Android 编译器是如何工作的?编译时会去掉 Java 代码和 Android XML 文件中的注释吗?
How does the Android compiler work? Does it remove the comments in Java code and Android XML files on compilation?
推荐答案
Java 文件中的注释在编译成类文件时会被删除或忽略.类文件不是供人类阅读的——它们经过优化以在虚拟机上高效运行.如果要保留注释,它们只会导致类文件大于所需的大小,并且没有额外的好处(即编译器和虚拟机不理解注释,所以为什么要包含它们)
Comments in Java files are removed, or ignored, when they are compiled into class files. Class files are not for human-reading - they are optimized to run efficiently on a virtual machine. If the comments were to remain, they would just cause the class files to be larger than required, and for no additional benefit (ie, the compiler and virtual machines don't understand comments, so why include them)
对于 XML 文件,通常会保留注释.编译后的类文件只有一个用途(在虚拟机上运行),而 XML 文件可以用于多种用途.例如,您可以将 XML 文件加载到应用程序中并对其进行操作.根据应用程序中 XML 文件的使用情况,可能需要在其中保留注释 - 事实上,您的应用程序可能会专门寻找注释.因为 XML 文件可以有广泛的用途,所以不会从 XML 文件中删除注释,以防它们被用于其他目的.
As for XML files, the comments are usually retained. Whereas a compiled class file only has 1 purpose (to run on a virtual machine), an XML file could serve many purposes. For example, you can load an XML file into your application and manipulate it. Depending on the use of the XML file in your application, it might be required to keep the comments in there - in fact, your application might specifically look for comments. Because XML files could have a wide range of uses, the comments aren't removed from XML files in case they are required for some other purpose.
这篇关于在Android中编译java文件后的注释会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在Android中编译java文件后的注释会发生什么?
基础教程推荐
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01