Forums Register Login

what is static import

+Pie Number of slices to send: Send
can any body explain me what is static import . If possible can provide code ...

thanks a lot .
+Pie Number of slices to send: Send
Java 1.5 Static Import.
+Pie Number of slices to send: Send
I never though that it would be such a simple thing .




both code are doing same thing , but in second case all the variable ( PI & E ) are being created locally for My class or in other word , we have a local copy of all the variable in My class .

Is this right ... and sufficient for beta ....

thanks a lot .
[ February 02, 2005: Message edited by: rathi ji ]
+Pie Number of slices to send: Send
There're few flaws in the code:
1. It should be import static
2. To import a static member like PI in Math, it should be

or


So be careful, don't get mixed up with normal import.
+Pie Number of slices to send: Send
It means , If we are importing a class then we will use * sign & If we are importing particular member ( variable only , method is not possible I think ) then we will not use * sign .

Is this right ?

Please reply .

Thanks a lot .
+Pie Number of slices to send: Send
one more thing Joyce , Why you wrote wildcard in this ...


thanks .
+Pie Number of slices to send: Send
Wildcard allows importing all the static members of Math class in one statement. Let's say, you want to import some static members like PI, min and max in Math, there are two approaches to do this:



or simply

+Pie Number of slices to send: Send
Hi rathi ji

i have sent u private message ..kindly reply it...


amit
+Pie Number of slices to send: Send
I have replied !!!
+Pie Number of slices to send: Send
Thanks Joycee ....

Is it possible to import static method() also .... I think not .. but please reply ..

thanks a lot ...
+Pie Number of slices to send: Send
Is it possible to import static method() also .... I think not .. but please reply ..

Yes, it's possible. max and min are static methods in Math class. You can also import a static nested class.

Here is an example:

Filename: StaticClass.java


Filename: TestStatic.java


Try compile the code and see the result.
+Pie Number of slices to send: Send
Another example using generic:

Filename: Outer2.java


Filename: TestOuter.java
+Pie Number of slices to send: Send


Joycee , How can you create an instance on static inner class without specifying outer class name .
I think the correct code should be this :


please reply ...

thanks .
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 918 times.
Similar Threads
Import duplicate class name .. different package
static import
import statement - Difference
Using enum values without typing the classname?
import
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:40:24.