Java 中的“导入"与 C/C++ 中的“#include" [英] 'import' in Java vs. '#include' in C/C++

查看:36
本文介绍了Java 中的“导入"与 C/C++ 中的“#include"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中的import"与 C/C++ 中的#include"的行为方式相同吗?具体来说,它会包含它正在导入的整个库还是只包含在后续代码中调用的类和方法?

Does 'import' in Java behave in the same way as '#include' in C/C++? Specifically, will it include the entire library that it is importing or will it just include the classes and methods that are called in the subsequent code?

推荐答案

#include 两者都不做,既不导入"库,也不导入"类或模块.

#include does none of both, neither "importing" libraries, nor classes or modules.

#include 指令只是告诉预处理器包含另一个文本文件(源)的内容.仅此而已.

The #include directive just tells the pre-processor to include the contents of another text file (source). That's all.

文件A的预处理结果#include将文件B作为一个文件传递给编译器,文件B粘贴到文件A的位置#include 指令已放置.

The result of pre-processing file A #includeing file B is passed to the compiler as if they were one file, with file B pasted into file A at the position where the #include directive was placed.

明确地说:这一切都发生在之前任何编译、代码生成.

To expliclity state this: This all happens prior to any compilation, code generation.

作为一个副作用,C/C++ 预处理器可以独立于编译器使用来处理任何类型的文本文件输入.

As a side effect the C/C++ pre-processor could be used independently from the compiler to process any kind of text file input.

有人可能会争辩说,像 #include 这样的预处理器语句实际上并不是 C/C++ 语言的一部分",因为它们本质上并不是用 C/C++ 编写任何程序所必需的,如它们永远不会传递给编译器.

One could argue that pre-processor statements like #include "are not really part of the C/C++ languages", as they are not essentially needed to write any programs in C/C++, as they are never passed to the compiler.

表达式 import 不用于(标准)C/C++ 编程的上下文中,因为没有要导入的内容.

The expression import is not used in the context of (standard) C/C++ programming, as there is nothing to be imported.

C/C++ 模块在源代码级别编译前或由链接器编译后放在一起.

C/C++ modules are put together either on source level prior to compilation or by the linker after compilation.

这篇关于Java 中的“导入"与 C/C++ 中的“#include"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆