can some tell me the difference between the import we use in java and the one in objective开发者_如何学编程 C?
In Java,
import long.package.name.Foo;
tells the compiler that any timeFoo
appears as aa class name in the current source file, it really meanslong.package.name.Foo
- so allimport
really does is allow you to write shorter source code. Finding class definitions is done via the convention of having class names match file names and package names match directory hierarchies.In Objective C, an
#import
statement is actually replaced with the contents of the imported file by the preprocessor, unless that file has already been imported (this is the difference between#import
and the older#include
directive).
#import
is a variant (that checks for duplication) of #include
, which just results in the contents of the included file being pasted in your source file.
Java's import statement tells the compiler where to look for classes (and other things) that are not qualified by their full name in the source code.
精彩评论