On 26 Jun., 16:06, Patricia Shanahan <p...@acm.org> wrote:
Karsten Wutzke wrote:
Hello,
I just compiled a class with a *static* import
import static org.domain.action.*;
but I don't get what this means. I had expected an error.
So, why does this compile? This would mean package-level constants... -
?
I tried this in Eclipse: import static java.util.*;
and got a reasonable error message "Only a type can be imported,
java.util resolves to a package". What compiler are you using?
Patricia
Don't know really. I'll have to check. I'm using the all-new Eclipse
3.5 inbuilt compiler.
I just realized the imports you tried don't compile for me either. I
seem to have tried something special:
The preamble for my class is
--
package com.kawoolutions.commons.action;
import java.util.*;
import static com.kawoolutions.commons.action.*; //same package as
above, no error
//import static com.kawoolutions.commons.action.CommonActions.*;
//import static com.kawoolutions.commons.action.CommonPrefixes.*;
//import static com.kawoolutions.commons.action.CommonSuffixes.*;
public class
IWantToUseConstantsFromClassesWithinThisPackageWithoutQualifying
{
...
}
--
So the special situation here seems to be that I was trying to do such
a static import from the same package to avoid the multiple imports
just for the specific classes. I was just trying it to save a few
lines to be honest. But why does this work? This should probably be an
error nonetheless, right?
none if I import static * the package containing the importing module. I
because of the "static".