Please say where you got those quotes from; they look vaguely familiar to me.
You don't import static methods, but static members. It is particularly intended for importing public static fields, which are usually marked "final" so they can be used as constants.
I fail to see why we are told to be sparing with it; I can't see how using lots of fields will cause confusion, but it would be better to import the members individually so one can see which class they come from.
Whilst saving a tiny bit of typing it does reduce readability of the code. I don't use them and discourage others from using them BUT somebody somewhere requested Sun to add them so they must find it useful. [ July 23, 2008: Message edited by: Paul Beckett ]
I'm leery of static imports as a rule, but when I was working with the RenderingHints class a while back, they suddenly became irresistible. But the justification I've heard most often is that mathematical formulas don't have to have to be cluttered with the "Math." prefix any more. So I guess static imports are a huge boon to the 0.01% of Java developers who do heavy math-based programming. [ July 23, 2008: Message edited by: Alan Moore ]
this can easily cause confusion and make it difficult to understand which class the method belongs to since we dont see the qualified name of any class nor any object ref variable
Not necessarily true - it's entirely possible to use static imports but not use wildcards. In that case, you will see the fully-qualified name of each method that you use, in the import statement. This quote is confusing the use of static imports in general with the use of wildcards. Not the same thing.
[Campbell]: You don't import static methods, but static members.
To be clear: "members" includes methods and fields, as well as nested classes and nested interfaces. Though nested classes and interfaces were already importable without the static import, so it's just (static) fields and methods that are affected by static import.
[Paul]: Whilst saving a tiny bit of typing it does reduce readability of the code.
Hm, that's a matter of opinion. Personally I think that this often improves the readability of code by reducing clutter.
[Alan]: So I guess static imports are a huge boon to the 0.01% of Java developers who do heavy math-based programming.
I always figured that Math was just an obvious example known to many people. Not necessarily the only one, just the best-known.
Joined: Jun 19, 2008
Thanks all for the responses .
The make up of the staements in quotes were purely my understanding after reading the details on sun site
Maybe I am sounding like an author ....... that's an encouraging sign for me
I am still not convinced of using a static import and using the "member" without the qualified class name.
I guess its a matter of opinion - but am curious if a poll were taken what % of the java community users would find this feature useful !