aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static imports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static imports" Watch "static imports" New topic
Author

static imports

Konda Golamaru
Ranch Hand

Joined: Dec 12, 2005
Posts: 36
Pls. clarify on below static imports.

import static java.lang.*;//generates the compilation error
cannot find symbol class lang

import static java.lang.System.out;//works fine
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The static import feature can only be used to import the static members of a class. You cannot use it the way you use a normal import statement where you import all .class files in a package.
ragavendran krishnamoothy
Greenhorn

Joined: Feb 13, 2007
Posts: 17
can you explain the static import concepts with some examples ..........
stating the advantages & restrictions of the concepts....
Apna Apana
Greenhorn

Joined: May 01, 2007
Posts: 20
hi
can you please explain in detail about static imports and also how they are useful.




Cheers
Apna
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Here is an example of using a static import.



As you can see the advantage of using the static import is that we do not have to use the classname Math when calling the method pow.

We can call the method as if it were defined in the class.
Apna Apana
Greenhorn

Joined: May 01, 2007
Posts: 20
Thank You Keith
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
import static java.lang.*;//generates the compilation error
cannot find symbol class lang



Hi Konda,
You cannot import all the members by saying "*" on the package.You have to explicitly import all the members.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static imports