Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, November 19, 2007

Java's import is not the same as C++'s #include

C++'s #include is commonly used to for library headers, but the mechanism which is used is fundamentally different. #include inserts the entire source file that is referenced into your C++ program. In contrast, the Java import statement only looks up the the identifiers and their declarations from the compiled class file (not the source files).

Another difference is that Java imports are non-transitive. If class A imports packagex and packagex imports packagey, class A does NOT get access to packagey. In C++, the imports are transitive, which can lead to some unexpected effects.

A minor difference is that Java's import is a statement and requires a semicolon, unlike C++.

No comments:

Post a Comment

Archives