Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IMPORTS Doubt

 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me the difference between static imports and ordianry imports
iam unable to solve questions from imports concept please
Thanks in advance
 
swapnil dangore
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sravanthi ,
With static import , you can import only static members of the class. So , no need to type classname to access members imported statically.


Regards
Swapnil
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey
the with ordianry import cant we import static members/?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sravanthi pulukuri:
Hey
the with ordianry import cant we import static members/?


No, that is why there is static import, otherwise what would be difference
between normal import and static import.

static import just gives a facility to avoid some keystrokes.
It enables us to use PI, E,etc constants of the Math class to be used directly without writing Math.PI or Math.E for example.



Thanks,
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks chandra
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So suppose if i use
import com.sun,scjp.class.*;
where in class is the file name,imports only the nonstatic members of the class??
then in that case i should use
import static com.sun.scjp.class.Enum;
Where in Enum is declared in the class and we can use constants present in Enum
Please clarify
 
venkata ramana sanku
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The static import construct allows unqualified access to static members without inheriting from the type containing the static members. Instead, the program imports the members, either individually:

import static java.lang.Math.PI;

or en masse:
import static java.lang.Math.*;


Once the static members have been imported, they may be used without qualification:
double x = cos(PI * theta);

The static import declaration is analogous to the normal import declaration. Where the normal import declaration imports classes from packages, allowing them to be used without package qualification, the static import declaration imports static members from classes, allowing them to be used without class qualification
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic