views:

78

answers:

2

can some tell me the difference between the import we use in java and the one in objective C?

+3  A: 
  • In Java, import long.package.name.Foo; tells the compiler that any time Foo appears as aa class name in the current source file, it really means long.package.name.Foo - so all import 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).

Michael Borgwardt
Does it mean that in Java, instead of writing "long.package.name.Foo" to represent a Foo, import helps us in referring it shortly.
Krishnan
@Krishnan: Yes, that's exactly what import does.
Michael Borgwardt
and that is all that it does. No magical side effects (like Perl's `use` can have for example) to be wary of.
Thilo
Thanks Thilo and Michael for the response.
Krishnan
+1  A: 

#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.

Thilo